问题描述
我想知道如何发出信号器件的应用是否推出的第一时间,或者已经推出之前。我想这样做的原因是为了显示一个很短信息的消息用过的应用程序之前,在应用程序启动没什么每个其他时间显示。我会放在App.xaml.cs类似如下
VAR设置= IsolatedStorageSettings.ApplicationSettings;
如果(settings.Contains(WasLaunched)!)
{
MessageBox.Show(第一次发动);
settings.Add(WasLaunched,真正的);
}
如果(!settings.Contains(WasLaunched )
导航到的第一个启动页相对于主页?有人能指出我在此实现任何有益的参考?
编辑**
我改变了我的 WMAppManifest.xml
默认页 LaunchPage的.xaml
< DefaultTask名称=_默认NavigationPage =LaunchPage.xaml/> ;
和创建了UriMapper类
公共类LoginUriMapper:UriMapperBase
{
公众覆盖乌里马普里(URI URI)
{
如果(uri.OriginalString ==/ LaunchPage的.xaml)
{
如果(Settings.FirstLoad.Value ==真)
{
//导航与快速第一次用户信息
URI来欢迎页=新的URI(/查看/ WelcomePage.xaml,UriKind.Relative);
}
,否则
{
///导航到实际的主页
URI =新的URI(/ MainPage.xaml中,UriKind.Relative);
}
}
返回URI;
}
}
但如何更改相应App.xaml.cs
私人无效Application_Launching(对象发件人,LaunchingEventArgs E)
{
//如何检查和导航为此具体方法正确的页面?
}
私人无效Application_Activated(对象发件人,ActivatedEventArgs E)
{
//如何检查并导航到正确的页面这个具体方法?
}
您最好使用
$的力量b$ b
的
其核心思想是:
您应该定义一个空白页( EntryPage.xaml
),并将它设置为你的应用程序的默认页。
然后在您的自定义 UriMapper
你重载马普里
方法。
公共类YourUriMapper:UriMapperBase
{
公众覆盖乌里马普里(URI URI)
{
如果(URI。 OriginalString ==/EntryPage.xaml)
{
VAR设置= IsolatedStorageSettings.ApplicationSettings;
如果(settings.Contains(WasLaunched)!)
{
URI =新的URI(/ FirstRunInfoPage.xaml,UriKind.Relative);
}
,否则
{
URI =新的URI(/ MainPage.xaml中,UriKind.Relative);
}
}
返回URI;
}
}
然后在应用程序初始化,你应该定义哪些 UriMapper
来使用:
私人无效Application_Launching(对象发件人,LaunchingEventArgs E)
{
RootFrame.UriMapper =新YourUriMapper();
}
私人无效Application_Activated(对象发件人,ActivatedEventArgs E)
{
如果(e.IsApplicationInstancePreserved ==假)
{
//墓碑!需要恢复状态
RootFrame.UriMapper =新YourUriMapper();
}
}
I am wondering how to signal whether an appication is launched for the very first time, or has already been launched before. The reason I want to do this is to show a very short informative message before the application is ever used, while every other time the application is launched nothing shows. Would I place something in App.xaml.cs like the following
var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("WasLaunched"))
{
MessageBox.Show("First time to launch");
settings.Add("WasLaunched", true);
}
And if (!settings.Contains("WasLaunched")
navigate to the 'first launch page' as opposed to the 'main page'? Can someone point me to any good references on this implementation?
EDIT**
I changed my WMAppManifest.xml
default page to LaunchPage.xaml
<DefaultTask Name="_default" NavigationPage="LaunchPage.xaml" />
And created my UriMapper class
public class LoginUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
if (uri.OriginalString == "/LaunchPage.xaml")
{
if (Settings.FirstLoad.Value == true)
{
//Navigate to Welcome Page with quick first time user info
uri = new Uri("/Views/WelcomePage.xaml", UriKind.Relative);
}
else
{
///Navigate to the actual Main Page
uri = new Uri("/MainPage.xaml", UriKind.Relative);
}
}
return uri;
}
}
But how do I change App.xaml.cs accordingly
private void Application_Launching(object sender, LaunchingEventArgs e)
{
//how to check and navigate to correct page for this specific method?
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
//how to check and navigate to correct page for this specific method?
}
You'd better to use the power of UriMapper
Here you can find a good article.
The core idea is:
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;
}
}
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();
}
}
这篇关于如何显示页面,如果应用程序启动的第一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!