简体   繁体   中英

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"));
}

As Shown above i have a Page and a PageFunction.

On PageButton_Click of Page.cs, i am navigating to PageFunction, But after the execution of the whole PageButton_Click event, a null reference exception (ie, Object reference not set to an instance of an object).

And i dont know why this exception ocurred.

Help me out with this problem.

Thanks.

请记住-> pagefunction<string>可能会对您有所帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM