如何在Settings_CommandsRequested上获取当前页面或框架? 我想从设置窗格导航。
答案 0 :(得分:1)
当前Frame
是您正在展示的那个,因此您可以定义如何访问它。您可以将实例引用保存为App类上的静态字段,也可以使用IoC容器来访问它。最简单的方法是对App类进行以下更新:
sealed partial class App : Application
{
public static Frame RootFrame { get; private set; }
...
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = this.RootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = this.RootFrame = new Frame();
...
然后,您只需致电App.RootFrame
即可获得您的相框。