我想写一个简单的方法来写入/读取WP7中的对象元素。有些东西工作不正常。我的思维方式和我已经做的是这样的:写入/读取对象
首先我创建一个代表我的对象的类。我添加静态字符串只是为了看看是否一切正常:
namespace SimpleObject.Objects
{
public class Entry
{
public string entrytitle { get; set; }
public string entrycomment { get; set; }
public string entrycat = "works";
public Entry() { }
public Entry(string Entrytitle, string Entrycomment, string Entrycat)
{
this.entrytitle = Entrytitle;
this.entrycomment = Entrycomment;
this.entrycat = Entrycat;
}
public string entry { get; set; }
}
}
然后,正如我在一些文章中,我需要在App.xaml.cs一些改变阅读在这里,我们然后去:
使用SimpleObject.Objects;
之前应用程序()我把这个:
公共静态条目E;
然后在应用程序()这样的:
UnhandledException += new EventHandler<ApplicationUnhandledExceptionEventArgs>(Application_UnhandledException);
E = new Entry();
InitializeComponent();
然后我的UI为两页。一种是输入数据的形式,另一种是读取数据。在应用程序栏按钮,我有:
private void ApplicationBarIconButton_Click(object sender, System.EventArgs e)
{
Entry E = new Entry
{
entrytitle = TitleTextBox.Text,
entry = CommentTextBox.Text,
};
this.NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
MessageBox.Show("Category added!");
}
最后页面,目前的研究结果:
private void button1_Click(object sender, RoutedEventArgs e)
{
TextBlock1.Text = App.E.entrycat;
TextBlock2.Text = App.E.entrytitle;
}
其次TextBlock的给我什么...
在此更改后,它们均未给出任何结果。 – dargod
我只能建议使用调试器。我的App.E的价值观是否被设置在第1页?当你碰到第2页的Button时他们还在吗?除非别的东西是覆盖值(或E本身),或者应用程序逻辑不完全是你发布的,那么它应该工作。 – ctacke
一般我想学习如何管理WP中的数据。你可以推荐任何好的教程? – dargod