所以我创建了一个名为“设置”的页面。显然,在此页面中是应用程序的设置。在“设置”页面中,我添加了2个ToggleSwitches和1个Listpicker。使用诺基亚开发者网站关于保存和阅读设置的基础知识我设法将其关闭,以便保存切换开关和列表选择器的状态。
我现在遇到的问题是,我需要一种方法在应用程序启动时在第一页上阅读这些保存的设置值,以便相应地准备应用程序。到目前为止这是我在“设置”页面中的内容:
Imports System.IO.IsolatedStorage
Partial Public Class Settings
Inherits PhoneApplicationPage
Private AppSettings As IsolatedStorageSettings
Public Sub New()
InitializeComponent()
AppSettings = IsolatedStorageSettings.ApplicationSettings
ListPicker1.Items.Add("Saved Notes")
ListPicker1.Items.Add("Important")
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
Try
Tg1.IsChecked = CBool(AppSettings("UseAccentColor"))
Tg2.IsChecked = CBool(AppSettings("GoBack"))
ListPicker1.SelectedIndex = CByte(AppSettings("StartListFalse"))
Catch ex As KeyNotFoundException
AppSettings.Add("UseAccentColor", False)
AppSettings.Add("GoBack", False)
AppSettings.Add("StartListFalse", False)
AppSettings.Save()
End Try
End Sub
Protected Overrides Sub OnNavigatedFrom(e As NavigationEventArgs)
System.Diagnostics.Debug.WriteLine("Exiting, so save now")
AppSettings("UseAccentColor") = Tg1.IsChecked
AppSettings("GoBack") = Tg2.IsChecked
AppSettings("StartListFalse") = ListPicker1.SelectedIndex
AppSettings.Save()
End Sub
End Class
所以太远了它在退出时保存,但我需要一种方法从启动,即我的MainPage加载这些。就像参考这个页面的方式一样,根据这些设置改变需要改变的内容。
我该怎么做? 谢谢!
答案 0 :(得分:1)
您设法将设置保存到IsolatedStorage,并且可以从应用程序的任何页面访问IsolatedStorage。所以在MainPage中,只需从IsolatedStorage而不是Settings Page中读取这些设置。
编辑: 您可以像设置页面中的OnNavigatedTo方法一样进行操作
Private AppSettings As IsolatedStorageSettings = IsolatedStorageSettings.ApplicationSettings
'Tg1.IsChecked is analog with useAccentColor
Dim useAccentColor As Boolean = CBool(AppSettings("UseAccentColor"))
'Tg2.IsChecked = goBack
Dim goBack As Boolean = CBool(AppSettings("GoBack"))
'ListPicker1.SelectedIndex = startListFalse
Dim startListFalse As Byte = CByte(AppSettings("StartListFalse"))