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() の前にこれを置きます:
public static エントリ E;
次に、App() で次のようにします。
UnhandledException += new EventHandler<ApplicationUnhandledExceptionEventArgs>(Application_UnhandledException);
E = new Entry();
InitializeComponent();
次に、私の UI は 2 ページです。1 つはデータを入力するためのフォーム、2 番目は読み取るためのフォームです。アプリケーションバーボタンの下に次のものがあります:
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;
}
そして、2番目の TextBlock は私に何も与えません...