How to Show a Page if Application is Launched for the First Time

后端 未结 2 1952
花落未央
花落未央 2020-12-18 16:35

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 s

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 17:11

    The best approach for the check is to write the status in the Isolated storage as you currently are. To redirect to the appropriate page, I would personally use a URI mapper. that way, your first intended entry page would be in the navigation first entry stack, preventing users from navigating back to the first page. A typical use case would be to redirect a user to a an authentication page when a user isn't authenticated and to a home page when the user is already authenticated, see This example

      public App()
        {
            SetUpLandingPageView();
        }
    
    
         void SetUpLandingPageView()
        {
            var isLaunched = IsolatedStorageSettings.ApplicationSettings.Contains("WasLaunched");
    
            // Get the UriMapper from the app.xaml resources, and assign it to the root frame
            var mapper = Resources["mapper"] as UriMapper;
    
            if (mapper == null) 
                throw new ArgumentNullException("Mapper must be configured");
    
            RootFrame.UriMapper = Resources["mapper"] as UriMapper;
    
            // Update the mapper as appropriate
            mapper.UriMappings[0].MappedUri = isLaunched ? new Uri("/Views/HomePage.xaml", UriKind.Relative) : new Uri("/Views/Introduction.xaml", UriKind.Relative);    
        }
    

    In the app.xaml

    Namespace:

    xmlns:UriMapper="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"
    

    Xaml

     
        
            
                
            
        
    
    

提交回复
热议问题