我想寫一個簡單的方法來寫入/讀取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