0

如何在 Settings_CommandsRequested 上获取当前页面或框架?我想从设置窗格导航。

4

1 回答 1

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来获取你的框架。

于 2013-03-14T17:03:13.773 回答