启动页设计要求和思路:
设计要求:打开应用时,首先加载启动页,在一定时间后跳转到首页,并去除后退按钮再次回到本页。注意:该过程并没有判断应用是否为第一次加载,如需判断,请留言。
设计思路:在WMAppManifest.xml页面中的导航页设置为启动页。(也可以在xml中设置,个人推荐可视化设置)
操作步骤:
1.设置你的导航页为启动页:
打开WMAppMainfest.xam。
设置启动页为导航页。
2.在你的启动页后台代码中添加应用:using System.Windows.Threading;
输入如下代码:
private DispatcherTimer timer;
public FirstIn()
{
InitializeComponent();
timer=new DispatcherTimer();
timer.Interval=new TimeSpan(0,0,0,2);
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
//处理事情
timer.Stop();
Uri uri=new Uri("/LogoIn.xaml",UriKind.RelativeOrAbsolute);
NavigationService.Navigate(uri);
//throw new NotImplementedException();
}
//重载导航页面
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
PhoneApplicationFrame myframe = Application.Current.RootVisual as PhoneApplicationFrame;
if (myframe != null)
{
try
{
myframe.RemoveBackEntry();
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
//throw;
}
}
}
注:OnNavigatedFrom事件和OnNavigatedTo的区别
在本次试用的是OnNavigatedFrom(跳转到其它页面前事件) 事件,因为导航到其他页面后移除返回按钮。(OnNavigatedTo是导航到本页后执行事件)
3.设计你的导航页面即可。