A-->B
B+--->A+
2 番目の .XAML ファイルに移動し、最初のファイルのデータを失うことなく戻る方法はありますか?
A-->B
B+--->A+
2 番目の .XAML ファイルに移動し、最初のファイルのデータを失うことなく戻る方法はありますか?
状態を保存し、IsolatedStorage に格納されるApplicationSettingsを使用します。これは、廃棄されてもデータを存続させたい場合に使用するものです。または、一時的な状態で状態を保持することもできます。
私が行う方法は、App.xaml.cs でいくつかのパブリック変数を宣言することです。
public partial class App : Application
{
public var item;
...
}
任意のページで ((App)(App.Current)).item として参照すると、別のページで変数にアクセスできます。
(一部の開発者は、グローバル変数を見てうんざりするかもしれませんが、まあ、うまくいきます)
私が最後にしたことは、リストボックスをグローバル文字列変数に保存し、値をコンマで区切ってから、グローバル streang 変数を読み取って、データをリストボックスに戻すことだけでした。
データを文字列に保存する
//creating a string array
string[] scores = new string[lsScore.Items.Count];
//filling the string array with the data from the listbox
lsScore.Items.CopyTo(scores, 0);
//filling a string with the joined values seperated by comma
string saveScores = string.Join(",", scores);
//saving the data to the global variable
saved.saveScores = saveScores;
文字列からデータを読み取る
// creating a an array and split the values from the global variable based on the comma
string[] scores2 = saved.saveScores.Split(',');
//adding the data to the lsitbox
foreach (string str in scores2)
lsScore.Items.Add(str);
Server.Urlcode(parameter) パラメータ値を使用すると、+、->、& などの特殊記号を記述した値になります。
例:Response.redirect("~/default2.aspx?data" +server.Urlcode(txtdata.text))