Use the variable in NavigationService.GoBack

NavigationService.GoBack() ; I set the variable in the viewmodel and then I want to return when I return. I want to use this variable, but nothing starts, I do not want to refresh this page.

Any ideas?

Here I set the variable and I want to return to my MainPage.

 void item_click(object sender, RoutedEventArgs e) { Button b = e.OriginalSource as Button; App.ViewModel.bName = b.Content.ToString(); App.ViewModel.bID = b.Name; this.NavigationService.GoBack(); } 

Here, in my MainPage, I want to run a check if the variables have changed.

 public MainPage() { /* i don't want to run this actually, when i'm coming back from my secondarypage. InitializeComponent(); InitializeSettings(); */ if (App.ViewModel.bName != null) { myButton.Content = App.ViewModel.bName; myButton.Name = App.ViewModel.bID; } } 
+7
source share
2 answers

I did not understand everything, but have you tried with the class "App" to declare a global variable for all pages instead of ViewModel?

Add, perhaps:

Using:

 (App)App.Current 

From this link: How to reference properties, a global variable in an application from another page for a Windows phone

+1
source

Oh, sorry for the vague question, but I solved my problem.

it was necessary on the main page.

 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { if (App.ViewModel.bName != null) { myButton.Content = App.ViewModel.bName; myButton.Name = App.ViewModel.bID; } base.OnNavigatedTo(e); } 
+1
source

All Articles