访问不同页面中的隔离存储数据

时间:2014-03-29 18:30:39

标签: c# windows-phone-8

我创建了一个IsolatedStorageSettings来存储播放器的数据 我在 SetProfile.xaml 页面

中创建了它

因此,在MainPage.xaml中,有一个TextBlock,其中包含一个文本" Hello"

我想做这样的事情:

TextBlock1.Text = "Hello " +(THE NAME OF THE PLAYER);

以及我需要访问隔离存储空间的地方 我怎么能这样做?

SetProfile.xaml

 IsolatedStorageSettings Profile = IsolatedStorageSettings.ApplicationSettings;

private void create_Click(object sender, RoutedEventArgs e)
       {
                Player player = new Player(); // Player is a class 
                player.FirstName = FirstName.Text;
                player.LastName = LastName.Text;
                player.Age = Convert.ToInt32(Age.Text);
                player.Rank = 1;
                player.RankDescreption = "Beginner";

                if (Profile.Contains("profile"))
                {
                    Profile.Remove("profile");
                    Profile.Add("profile", player);
                    Profile.Save();
                }

                else
                {
                    Profile.Add("profile", player);
                    Profile.Save();
                }

                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }


  private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
        {
           if (IsolatedStorageSettings.ApplicationSettings.Contains("profile"))
               NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }

MainPage.xaml中

private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
    {
        HelloName.Text = "Hello " + (WHAT I NEED) ;
    }

1 个答案:

答案 0 :(得分:1)

你可以这样读取设定值:

private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
    {
    if (IsolatedStorageSettings.ApplicationSettings.Contains("profile"))
       {
         Player player =(Player)IsolatedStorageSettings.ApplicationSettings["profile"];         
        HelloName.Text ="Hello"+ player.FirstName;
       }      
    }

click in this doc to know more about settings