WPF - 从帧内部访问Frame的BackStack属性

时间:2021-01-09 15:52:47

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?

我有一个通过它的Source属性加载到Frame元素内的Page。我需要从源代码xaml的代码隐藏中访问Frames .BackStack属性......这可能吗?

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.

在ProjectsPage.xaml.cs中,我想访问其父框架上的属性。

2 个解决方案

#1


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.

导航历史是WPF严重缺陷的一个领域。不,我不相信有任何方法可以从页面获取Frame的BackStack。如果你不需要这样做,你可以实施一些黑客攻击。挂钩Frame的导航事件,并在导航到的任何DependencyObject上为Frame设置附加的依赖项属性。不幸的是,你用BackStack做的事情并不多,但我认为你已经确定它已经足够好用于你正在做的事情了。

#2


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.

如果您使用NavigationService.GetNavigationService并从ProjectsPage中传入一个元素,您可以在Frame的NavigationService*问诸如CanGoBack和GoBack之类的东西,这些东西可以让您实现与BackStack本身一样多的功能。

#1


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.

导航历史是WPF严重缺陷的一个领域。不,我不相信有任何方法可以从页面获取Frame的BackStack。如果你不需要这样做,你可以实施一些黑客攻击。挂钩Frame的导航事件,并在导航到的任何DependencyObject上为Frame设置附加的依赖项属性。不幸的是,你用BackStack做的事情并不多,但我认为你已经确定它已经足够好用于你正在做的事情了。

#2


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.

如果您使用NavigationService.GetNavigationService并从ProjectsPage中传入一个元素,您可以在Frame的NavigationService*问诸如CanGoBack和GoBack之类的东西,这些东西可以让您实现与BackStack本身一样多的功能。