Windows 8 如何使用带有母版页的CharmFlyoutLibrary?
我有一个Windows8应用程序,最近我对它进行了重构以使用“母版页”。这意味着有一个“布局”包含一些通用组件,如页眉和页脚。在这个布局中,我有一个框架。每次我想显示不同的视图时,我都会将其加载到框架中 这意味着我的启动屏幕不再是Windows 8 如何使用带有母版页的CharmFlyoutLibrary?,windows-8,windows-runtime,master-pages,mvvm-light,charms-bar,Windows 8,Windows Runtime,Master Pages,Mvvm Light,Charms Bar,我有一个Windows8应用程序,最近我对它进行了重构以使用“母版页”。这意味着有一个“布局”包含一些通用组件,如页眉和页脚。在这个布局中,我有一个框架。每次我想显示不同的视图时,我都会将其加载到框架中 这意味着我的启动屏幕不再是Frame类型,而是Layout类型,这是一个LayoutAwarePage。这是我在App.xaml.csOnLaunched中初始化它的方式: Layout rootFrame=Window.Current.Content作为布局; if(rootFrame==nu
Frame
类型,而是Layout
类型,这是一个LayoutAwarePage
。这是我在App.xaml.csOnLaunched
中初始化它的方式:
Layout rootFrame=Window.Current.Content作为布局;
if(rootFrame==null)
{
rootFrame=新布局();
问题来了:我有一个charms弹出按钮,其中包含一些设置之类的项目。我创建了一个很好的视图(Flayouts.xaml),其中包含这些弹出按钮的布局。该视图背后的代码如下所示:
公共弹出按钮()
{
初始化组件();
SettingsPane.GetForCurrentView().CommandsRequested+=弹出按钮\u CommandsRequested;
}
无效弹出按钮\u请求的命令(设置spane发送器、设置spaneCommand和srequestedeventargs args)
{
//添加一些命令
}
这就是您如何在应用程序中实现此功能的方法:
Frame rootFrame=Window.Current.Content作为Frame;
if(rootFrame==null)
{
rootFrame=new CharmFlyoutLibrary.CharmFrame{CharmContent=new Flyouts()};
他们在这里做的是将框架
分配给“rootFrame”。然而,自从我切换到母版页后,我不再有框架
,而是一个布局
/布局页面
类型,因此我无法将CharmFrame分配给它。如何克服这个问题
有人吗?在框架内导航时,您导航到的页面将放置在“导航内容”属性内 因此,如果您首先导航到布局,那么内容将被您的页面填充,您可以导航到您的子页面
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");
}
}
}