我们如何直接导航第2页(第2页)我的意思是不使用c#.net在Windows Phone 8中打开第1页(第1页) [英] How can we navigate directly 2nd page(Page 2) i mean not open 1st page(Page 1) in Windows phone 8 using c#.net

查看:59
本文介绍了我们如何直接导航第2页(第2页)我的意思是不使用c#.net在Windows Phone 8中打开第1页(第1页)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生/女士,

按照我的项目要求...用户打开wp8 myApp ..第一次注册时使用的是电话号码和密码。现在我是我写了一个电话号码和密码的文件。现在他导航到第二页,在他完成工作后,他退出
即myApp。

As per my project requirement ... User open the wp8 myApp..first time he is registered with phone number and password.Now i am write a file that phone number and password.Now he is navigate to second page and after he completion of his work,he is exit from that myApp.

第二次他打开myApp,他读取该文件并从该文件中获取数据。如果有可用数据,则直接打开第二页(第2页)不显示注册页面。

Second time he is open that myApp,he is read that file and get data from that file .If there is data available then directly open the Second page(Page2) not display the Registration Page.

我写的此代码

 public MainPage()
        {
            InitializeComponent();
            
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
            string fileData = LoadFromFile();

            if (fileData != "")
            {
                try
                {
                    ClassMyCity.csRegisteredFullData = fileData;
                    NavigationService.Navigate(new Uri("/myCityLogin.xaml", UriKind.Relative));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Navigation page Exception:-" + ex);

                }
            }
            
           
        } 


public string LoadFromFile()
        {
            //Setting the fileName
            var fileName = "myCityRegisteredDataFile3.dat";
            try
            {
                ///<summary>
                ///get the user Store and then open the file in the store
                ///finally read the content to the file and return it
                ///</summary>
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                using (var readStream = new IsolatedStorageFileStream(fileName, FileMode.Open, store))
                using (var reader = new StreamReader(readStream))
                {
                    return reader.ReadToEnd();
                }
            }
            catch (IsolatedStorageException e)
            {
                //IsolatedStorageException catch if File cant be opened
                MessageBox.Show("What is your name?");
                return String.Empty;
            }
        }

请解决我的问题。这对我来说很迫切。

Please solve my problem.It is urgent requirement to me.

谢谢&问候,

SrinivaaS。

SrinivaaS.

推荐答案

您可以创建一个Uri Mapper,继承自
UriMapperBase class
,如果存储文件不存在,请检查并导航到"用户初始化"页面。  (

自动启动应用程序walk-trough
有一个实现和设置Uri映射器的示例。)

You could create a Uri Mapper, inherit from UriMapperBase class, to check and navigate to your 'user initialization' page if the storage file does not exist.  (The Auto-launching apps walk-trough has an example of implementing and setting up a Uri mapper.)

in以下 示例"Page1.xaml"用户输入信息的地方。 

in the following example "Page1.xaml" would be where your user enters their information. 

    class AssociationUriMapper : UriMapperBase
    {
        private string tempUri;
        private string fileData;

        public AssociationUriMapper()
        {
            fileData = this.LoadFromFile();
        }

        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();
            if (String.IsNullOrEmpty(fileData))
            {
                fileData = this.LoadFromFile(); // retry once.
            }
            if (String.IsNullOrEmpty(fileData))
            {
                return new Uri("/Page1.xaml", UriKind.Relative);
            }
            // else map normally.
            return uri;
        }
        private string LoadFromFile()
        {
            //Setting the fileName
            const string fileName = "myCityRegisteredDataFile3.dat";
            try
            {
                ///<summary>
                ///get the user Store and then open the file in the store
                ///finally read the content to the file and return it
                ///</summary>
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                  using (var readStream = new IsolatedStorageFileStream(fileName, System.IO.FileMode.Open, store))
                    using (var reader = new System.IO.StreamReader(readStream))
                    {
                        return reader.ReadToEnd();
                    }
            }
            catch (Exception)
            {
                return String.Empty;
            }
        }
}


这篇关于我们如何直接导航第2页(第2页)我的意思是不使用c#.net在Windows Phone 8中打开第1页(第1页)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆