微软的文章(http://msdn.microsoft.com/en-us/library/windows/apps/hh994639.aspx)指出,您可以创建一个扩展的闪屏页面,在此期间您可以创建MainPage,然后在加载后导航到该页面。
唯一的问题是,在将页面设置为Window.Current.Content
属性之前,永远不会触发页面的Loaded事件。
有谁有解决这个问题的办法吗?-我的MainPage有相当多的XAML,需要一段时间才能加载到低端设备上。
发布于 2012-10-15 17:27:51
默认情况下,应用程序在其可视根目录下有一个框架控件。你可以修改它,例如把你自己的UserControl (我通常叫它AppShell)放在里面,它有所有页面使用的框架,你可以有一个用于弹出窗口,登录屏幕等的层,或者扩展的闪屏。
要解决您的问题-只需将框架和扩展的splash控件都放在一个网格中,并仅在加载扩展的splash控件后导航到第一页。那么其他的一切都应该是简单的。
发布于 2012-10-15 18:20:11
如果您使用MainPage类似于ASP.NET中的MasterPage,那么MainPage应该有APP Bar定义,并且在正文中应该只包含一个Frame元素。使用此模式设置应用程序的内容,而不是
Window.Current.Content = // An Application Page
use
AppFrame.Content = //An Application Page
还要考虑从Mainpage元素中删除您的主页面代码,并将其放入一个自定义用户控件中,然后您就可以从userControl中创建一个事件,供MainPage处理。它还允许您在应用程序的其他地方使用该功能,而无需完全重新创建逻辑和UI。
下面是MainPage的XAML示例:
<Page.Resources>
<ResourceDictionary x:Name="CommonStyles" Source="/Common/StandardStyles.xaml" />
</Page.Resources>
<Page.TopAppBar>
<AppBar x:Name="NavigationAppBar" Padding="10,0,10,0" AutomationProperties.Name="Global App Bar" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel x:Name="LeftCommands" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">
<!-- App Bar Buttons Removed -->
</StackPanel>
</Grid>
</AppBar>
</Page.TopAppBar>
<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
使用Getter和Setter将类型为Frame的公共属性添加到应用程序视图模型
public Frame SelectedAppFrame {get;set;}
在MainPage.xaml.cs文件中,指定一个属性:
ApplicationViewModel vm = this.PageBackgroundGrid.DataContext as ApplicationViewModel;
vm.SelectedAppFrame = this.AppFrame;
App View Model中的泛型导航代码是:
public void HandleNavigaitionEvent(object sender, string pageName, Frame AppFrame, StackPanel stack)
{
var content = Pages.Where(i => i.Name == pageName).FirstOrDefault();
NavigateTrigger(AppFrame, content);
}
public void NavigateTrigger(Frame AppFrame, LayoutAwarePage content)
{
EventAggregator.GetEvent<PageNavigatedEvent>().Publish(content);
AppFrame.Content = content;
NaviagationPath.Add(content);
}
这样,您就可以从应用程序中可访问ApplicationViewModel的任何位置(应该是所有位置)将更改传播到AppFram中。
https://stackoverflow.com/questions/12885216
复制相似问题