隔离存储在多页c#中

Isolated storage in In a multi-page c#

我在应用程序中创建了两个页面... 在首页 Tkstpeix 进入存储时写下您的名字,并在此页面上设置应用程序, 而且当你进入第二个页面的时候应用名不出来!

示例: 当我打开应用程序并输入我的名字 "Ibra" 时,第二页的 文本框 没有出现我的名字!

->第1页:

using myProject.Model;
public partial class Test1 : PhoneApplicationPage
{
    IsolatedStorageSettings Data = IsolatedStorageSettings.ApplicationSettings;
    List<UserData> ObjUserDataList = new List<UserData>();
    public Test1()
    {
        InitializeComponent();
        this.Loaded += Test1_Loaded;
    }

    private void Test1_Loaded(object sender, RoutedEventArgs e)
    {
        if (Data.Contains("UserNameData"))
        {
            NavigationService.Navigate(new Uri("/Test2.xaml", UriKind.Relative));
        }
    }

    private void NameBox_GotFocus(object sender, RoutedEventArgs e)
    {
        TextBox tb = (TextBox)sender;
        tb.BorderBrush = new SolidColorBrush(Colors.LightGray);
    }

    private void button_Click(object sender, RoutedEventArgs e)
    {
        Data["UserNameData"] = NameBox.Text;
        NavigationService.Navigate(new Uri("/Test2.xaml", UriKind.Relative));
    }
}

-->第2页:

using myProject.Model;
public partial class Test2 : PhoneApplicationPage
{
    IsolatedStorageSettings Data = IsolatedStorageSettings.ApplicationSettings;
    UserData ObjUserData = new UserData();
    public Test2()
    {
        InitializeComponent();
        this.Loaded += Test2_Loaded;
    }

    private void Test2_Loaded(object sender, RoutedEventArgs e)
    {
        if (Data.Contains("UserNameData"))
        {

            StckUserDetailsUI.DataContext = ObjUserData;
        }
    }
}


<StackPanel  Name="StckUserDetailsUI"  Grid.Row="0" Margin="12,17,0,28" Grid.ColumnSpan="2">
            <TextBlock Text="Your Details :" Foreground="White" FontSize="30" TextDecorations="Underline"/>
            <TextBlock FontSize="40" Name="TxtUserName" Text="{Binding UserName}" Foreground="White"/>
        </StackPanel>

--->UserData.Cs: (在文件/Model中)

 class UserData
{
    public string UserName { get; set; }
}

注意: 我在 windows phone 8.1 silverlight

工作

您将 DataContext 设置为 ObjUserData,但您从未为 ObjUserData.UserName 添加任何内容,因此它返回为空白。