当前位置: 首页 > 编程语言 > C#

如果首次启动应用程序,如何显示页面分享

时间:2023-04-10 21:25:29 C#

C#LearningTutorial:Howtodisplayapageshareiftheapplicationislaunchedforfirsttime我想这样做的原因是在使用该应用程序之前显示一个非常简短的信息消息,而不是在每次应用程序启动时显示它.我会在App.xaml.cs中放入类似的内容varsettings=IsolatedStorageSettings.ApplicationSettings;if(!settings.Contains("WasLaunched")){MessageBox.Show("首次启动");settings.Add("WasLaunched",true);如果(!settings.Contains("WasLaunched")导航到“FirstLaunchPage”而不是“HomePage”?任何人都可以指出我对这个实现的任何好的参考吗?编辑**我将WMAppManifest.xml默认页面更改为LaunchPage.xaml并创建了我的UriMapper类publicclassLoginUriMapper:UriMapperBase{publicoverrideUriMapUri(Uriuri){if(uri.OriginalString=="/LaunchPage.xaml"){if(Settings.FirstLoad.Value==true){//NavigatetoWelcomePagewithquickfirsttimeuserinfouri=newUri("/Views/WelcomePage.xaml",UriKind.Relative);}else{///导航到实际主页uri=newUri("/MainPage.xaml",UriKind.Relative);}}returnuri;}}但是如何相应地更改App.xaml.cs方法?}privatevoidApplication_Activated(objectsender,ActivatedEventArgse){//如何检查并导航到此特定方法的正确页面?你最好使用UriMapper的强大功能在这里你可以找到一篇好文章核心思想是:你应该定义一个空页面(EntryPage.xaml)并将其设置为应用程序的默认页面。然后在您的自定义UriMapper中覆盖MapUri方法。publicclassYourUriMapper:UriMapperBase{publicoverrideUriMapUri(Uriuri){if(uri.OriginalString=="/EntryPage.xaml"){varsettings=IsolatedStorageSettings.ApplicationSettings;如果(!settings.Contains("WasLaunched")){uri=newUri("/FirstRunInfoPage.xaml",UriKind.Relative);}else{uri=newUri("/MainPage.xaml",UriKind.Relative);}}返回uri;然后在应用程序初始化时,您应该定义要使用的UriMapper:privatevoidApplication_Launching(objectsender,LaunchingEventArgse){}privatevoidApplication_Activated(objectsender,ActivatedEventArgse){if(e.IsApplicationInstance==fPreserved){//逻辑删除!需要恢复状态RootFrame.UriMapper=newYourUriMapper();最好的检查方法是将状态写入您当前拥有的独立存储中。要重定向到适当的页面,我个人会使用URI映射器。这样,您的第一个预期输入页面将位于导航第一个入口堆栈中,从而防止用户导航回第一页。一个典型的用例是在用户未通过身份验证时将用户重定向到经过身份验证的页面,并在用户已通过身份验证时将用户重定向到主页,请参阅此示例publicApp(){SetUpLandingPageView();}voidSetUpLandingPageView(){varisLaunched=IsolatedStorageSettings.ApplicationSettings.Contains("WasLaunched");//从app.xaml资源中获取UriMapper,并将其分配给根框架varmapper=Resources["mapper"]asUriMapper;if(mapper==null)thrownewArgumentNullException("必须配置Mapper");RootFrame.UriMapper=Resources["mapper"]asUriMapper;//适当更新映射器mapper.UriMappings[0].MappedUri=isLaunched?newUri("/Views/HomePage.xaml",UriKind.Relative):newUri("/Views/Introduction.xaml",UriKind.Relative);}namespaceinapp.xaml:xmlns:UriMapper="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"XAML以上是C#学习教程:如果是第一次启动应用,如何显示页面分享的所有内容,如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注——这篇文章收集自网络,不代表立场,如涉及侵权,请点击右侧联系管理员删除,如需转载请注明出处: