ページ間に単純な文字列を渡そうとしていますが、わかりません。ページ間でデータを渡すC#WPF
私はボタンをクリックし、テストアプリ、「」今、次のページ(Page1.xaml.cs)
private void button1_Click(object sender, RoutedEventArgs e)
{
string a = "hello";
Page2 p2 = new Page2();
NavigationService.Navigate(p2, a);
}
に渡します、私はデータを抽出したいの値を作成ページ1(Page2.xaml.cs)から
private void NavigationService_LoadCompleted(object sender, NavigationEventArgs e)
{
string str = (string)e.ExtraData;
}
そして、しかし、私コンストラクタ(Page2.xaml.cs)
public Page2()
{
InitializeComponent();
NavigationService.LoadCompleted += NavigationService_LoadCompleted;
}
にサブスクライブ私はエラーが発生したプログラムを走らせた。誰かが私が逃しているものを指摘できますか?
すでに同様の質問があります。[ここ]です(http://stackoverflow.com/questions/37955612/how-can-i-transfer-parameter-from-one-page-to)。 -another/37977367#37977367)。 –