Reputation: 29
NavigationService.GoBack()
; I'm setting a variable in viewmodel and then I want to go back, when I'm back I want to use that variable, but nothing seems to run, I don't want to refresh that page.
Any ideas?
Here i'm setting variable, and i want to go back 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 the check to se if variables has 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;
}
}
Upvotes: 7
Views: 1306
Reputation: 3979
I do not have understood everything but have you tried with the "App" class to declare a variable global to all pages instead of ViewModel?
Add maybe :
Use:
(App)App.Current
From this link: How to reference properties, global variable in app from other page for windows phone
Upvotes: 1
Reputation: 29
oh i'm sorry for the vague question, but i solved my problem.
this was needed in the mainpage.
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);
}
Upvotes: 1