Object reference error in NavigationService.Navigate

后端 未结 2 880
甜味超标
甜味超标 2021-01-21 22:04

Inside my MainPage constructor I\'m using NavigationService to navigate to another page, but I\'m getting the error:

object refe

相关标签:
2条回答
  • 2021-01-21 22:48

    The page you're navigating to hasn't yet been created in the c'tor. "Loaded" fires after the objects are all created, and is the right spot for doing things like navigating to another page and such.

    0 讨论(0)
  • 2021-01-21 22:49

    A little late to the party, but from what MSDN says (and mentioned by @JustinAngel's comment above), you should actually use the OnNavigatedTo event, rather than Loaded. While Loaded still works,

    Typically, you use the OnNavigatedTo method instead of creating an event handler for the Loaded event. The OnNavigatedTo method is preferable because it is only called once for each time the page becomes active. The Silverlight framework raises the Loaded event each time the element is added to the visual tree, which potentially can happen more than once when activating a page.

    0 讨论(0)
提交回复
热议问题