Question

I have a Page which is loaded inside a Frame element via it's Source property. I need to get access to the Frames .BackStack property from the source xaml's code-behind... Is that possible?

so roughly the code is -

<Frame x:Name="contentFrame" Source="ProjectsPage.xaml"/>

in the ProjectsPage.xaml.cs i want to access properties on its parent frame.

Was it helpful?

Solution

Navigation history is one area in which WPF is sorely deficient. No, I don't believe there's any way to get at the BackStack of the Frame from the page. You could implement a bit of a hack, if you don't need to do this generically. Hook the navigation events of the Frame, and set an attached dependency property to the Frame on any DependencyObject that's navigated to. Unfortunately, there's not much you can do with the BackStack, but I assume you've already determined it's good enough for what ever you're doing.

OTHER TIPS

If you use NavigationService.GetNavigationService and pass in an element from within ProjectsPage, you can access things like CanGoBack and GoBack on your Frame's NavigationService that let you accomplish almost as much as having the BackStack itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top