Silverlight 頁面之間傳值的。主要是使用獨立存儲的IsolatedStorageSettings對象,首先需要創建對象
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
然後在Button事件中加入如下代碼,用於傳值
if (!appSettings.Contains("Ope"))
appSettings.Add("Ope", "UserName");
可以用上述方法創建多個要傳到目標頁面的參數
OK了,在目標頁面獲取值的方式就簡單了
if (appSettings.Contains("Ope"))
txbShowvalue.Text = "User Name: " + appSettings["Ope"].ToString();
需要注意的一點是這個獲取值的代碼不要寫在頁面的構造函數裏面,有可能不會觸發,原因是在上面對象已經保存在內存中了,但是會觸發Loaded事件,因此可以把代碼放到這個事件裏面
第二種方法
MainPage頁面中
Resources.Remove("Ope");
Resources.Add("Ope", txtLoginName.Text);
接收頁面
MainPage p = Application.Current.RootVisual as MainPage;
string s = p.Resources["Ope"] as string;
txtCuOpe.Content = s;