Why is NavigationService null in Page constructor?

时间:2015-06-30 19:26:53

标签: c# wpf

I have a NavigationWindow that hosts pages. When navigating to a Page, in its constructor, calling NavigationService.GetNavigationService(this) yields null, but in the Page_Loaded event it returns the desired object.

The thing is, regardless which page is loaded, the NavigationService object is the same. I checked this using GetHashCode().

So if it really is the same object every time, why does it have to be null in the Page constructor? And why do I have to pass a DependencyObject, when it returns the same object anyway?

Is there anything that prevents me from assigning the NavigationService object to a static variable and reuse it?

0 个答案:

没有答案