简体   繁体   中英

How to restart a page in C# for Windows Phone 7?

I restarted a page, Game.xaml using

NavigationService.Navigate(new Uri(string.Format("/Game.xaml?random={0}", Guid.NewGuid()), UriKind.Relative));

However, for now, I have to restart the page depends on the value that I selected a page before. To get the value that I selected a page before, I used

int selectedLevel = Convert.ToInt32(NavigationService.GetLastNavigationData());

Game.xaml will displayed the data depends on the value that I choosen a page. But if I restart the page now, no data is displayed. Does anyone know how can I do it?

How about adding a global variable in App.xaml.cs?

public string Variable { get; set; }

(App.Current as App).Variable = "Hi i'm global";

I had to reinstantiate the page by the following

            //Refresh homepage
            InitializeComponent();
            NavigationService.Navigate(new Uri("pageURI", UriKind.Relative));´

pageURI should be changed to the page you want to reinstantiate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM