在Silverlight 5中使用IsolatedStorage保存用户设置(vb)

时间:2012-10-24 18:37:44

标签: silverlight-5.0 silverlight-oob

我想保存TextBox中的值,SelectedIndexComboBox的{​​{1}}和CheckBox选中的真或假。然后,我想从一个按钮调用OnClick保存的设置。我已经使用下面的TextBox,但是我收到以下错误声明:KeyNotFoundException未被用户代码处理。给定的密​​钥不在现在的字典中?

有人能帮助我吗?

Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)    Handles Button2.Click

    Dim Store As IsolatedStorageSettings = IsolatedStorageSettings.ApplicationSettings

    IsolatedStorageSettings.ApplicationSettings(TextBox1.Text) = TextBox1
End Sub

Private Sub Button3_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button3.Click

    TextBox1 = (IsolatedStorageSettings.ApplicationSettings(TextBox1.Text))

End Sub

1 个答案:

答案 0 :(得分:0)

ApplicationSettings的工作方式类似于Hashtable。它需要一个键来识别您想要存储的任何设置。

您可以像这样存储您的设置(航空代码):

IsolatedStorageSettings.ApplicationSettings("MyTextBoxKey") = TextBox1.Text

您可以像这样检索您的设置:

TextBox1.Text = CStr(IsolatedStorageSettings.ApplicationSettings("MyTextBoxKey"))

你可以read more about the ApplicationSettings on MSDN