[英]Navigating from Page/ Page Function to PageFunction Null Reference Exception occurs
Page.cs
private void PageButton_Click(object sender, RoutedEventArgs e)
{
PageFunction pageFunction = new PageFunction();
pageFunction.Return += new ReturnEventHandler<String>(pageFunction_Return);
this.NavigationService.Navigate(pageFunction);
}
static void pageFunction_Return(object sender, System.Windows.Navigation.ReturnEventArgs<String> e)
{
String returnedVaule = e.Result;
MessageBox.Show(returnedVaule);
}
PageFunction.cs
private void PageFunctionButton_Click(object sender, RoutedEventArgs e)
{
OnReturn(new ReturnEventArgs<string>("Returned"));
}
如上圖所示,我有一個Page和一個PageFunction。
在Page.cs的PageButton_Click上,我導航到PageFunction,但是在執行整個PageButton_Click事件后,出現空引用異常(即,對象引用未設置為對象的實例)。
而且我不知道為什么會發生這種異常。
幫我解決這個問題。
謝謝。
請記住-> pagefunction<string>
可能會對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.