【问题标题】:How to use CharmFlyoutLibrary with master page?如何将 CharmFlyoutLibrary 与母版页一起使用?
【发布时间】:2013-11-12 02:37:19
【问题描述】:

我有一个 Windows 8 应用程序,最近我将它重构为使用“母版页”。这意味着存在一个“布局”,其中包含一些通用组件,例如页眉和页脚。在那个布局中,我有一个框架。每次我想显示不同的视图时,我都会将其加载到框架中。

这意味着我的启动屏幕不再是Frame 类型,而是Layout 类型,即LayoutAwarePage。这就是我在 App.xaml.cs OnLaunched 中初始化它的方式:

Layout rootFrame = Window.Current.Content as Layout;

if (rootFrame == null)
{
    rootFrame = new Layout();

问题来了:我有一个超级按钮弹出窗口,其中包含一些项目,例如设置。我制作了一个漂亮的视图 (Flayouts.xaml),其中包含这些浮出控件的布局。该视图的代码如下所示:

public Flyouts()
{
    InitializeComponent();

    SettingsPane.GetForCurrentView().CommandsRequested += Flyouts_CommandsRequested;
}

void Flyouts_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    // add some commands
}

这就是你如何让它在你的应用中工作:

Frame rootFrame = Window.Current.Content as Frame;

if (rootFrame == null)
{
    rootFrame = new CharmFlyoutLibrary.CharmFrame { CharmContent = new Flyouts() };

他们在这里所做的是将Frame 分配给“rootFrame”。但是,由于我切换到母版页,我不再有 Frame 而是 Layout/LayoutAwarePage 类型,所以我无法将 CharmFrame 分配给它。我该如何克服这个问题?

有人吗?

【问题讨论】:

    标签: windows-8 windows-runtime master-pages mvvm-light charms-bar


    【解决方案1】:

    在框架内导航时,您导航到的页面将放置在导航内容属性中。

    因此,如果您先导航到布局,那么内容将充满您的页面,您可以导航到您的子页面。我在下面放了一个例子

            Frame 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 = new Frame();
    
                //Associate the frame with a SuspensionManager key                                
    
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
    
                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) {
                    // Restore the saved session state only when appropriate
                    try {
                        await SuspensionManager.RestoreAsync();
                    } catch (SuspensionManagerException) {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }
    
                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null) {
                if (rootFrame.Navigate(typeof(Layout))) {
                    var secondFrame = rootFrame.Content as Layout;
                    if (!secondFrame.ContentFrame.Navigate(typeof(YourPage)) {
    
                    throw new Exception("Failed to create initial page");
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多