更新时间:2023-01-25 21:45:03
你***利用UriMapper
核心思想是:
您应该定义一个空页面 (EntryPage.xaml
) 并将其设置为应用的默认页面.然后在您的自定义 UriMapper
中重载 MapUri
方法.
You should define an empty page (EntryPage.xaml
) and set it as a default page of your app.
Then in your custom UriMapper
you overload the MapUri
method.
public class YourUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
if (uri.OriginalString == "/EntryPage.xaml")
{
var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("WasLaunched"))
{
uri = new Uri("/FirstRunInfoPage.xaml", UriKind.Relative);
}
else
{
uri = new Uri("/MainPage.xaml", UriKind.Relative);
}
}
return uri;
}
}
然后在应用程序初始化时,您应该定义要使用的 UriMapper
:
Then on app initialization you should define which UriMapper
to use:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
RootFrame.UriMapper = new YourUriMapper();
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
if (e.IsApplicationInstancePreserved == false)
{
// tombstoned! Need to restore state
RootFrame.UriMapper = new YourUriMapper();
}
}