我想用一种简单的方法来写入/读取 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;
在 App() 之前我放了这个:
公共静态条目 E;
然后在 App() 中:
UnhandledException += new EventHandler<ApplicationUnhandledExceptionEventArgs>(Application_UnhandledException);
E = new Entry();
InitializeComponent();
然后我的用户界面是两页。一是表格输入数据,二是读取。在应用程序栏按钮下,我有:
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 什么也没给我...