在多页c#中隔离存储

时间:2015-08-07 19:38:35

标签: c# windows-phone-8.1 iso

我在应用程序中创建了两个页面...... 在首页上,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));
    }
}

- &GT;第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>

---&gt; UserData.Cs :(在文件/模型中)

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

请注意: 我在windows phone 8.1 silverlight工作

1 个答案:

答案 0 :(得分:2)

您将Smith设置为DataContext,但您从未为ObjUserData添加任何内容,因此它会以空白状态返回。