I have a settings page on my app that has change language option. How can I reload the strings on the previous page when I change the language and navigate back to it with PopAsync() function?
You can override your page's OnAppearing() method. This will be called when the other page is popped away.
Okay, that was helpful. I will probably use MessagingCenter, but what is the best approach to reload the content. Do I have to write all the containers and layouts and add them to the main Content property? Or I can just reload somehow the page itself?
The best approach is to use bindable properties / observable collections, common in MVVM pattern. Then you just need to update your ViewModels data, which will update the view.
Other than that, you can force it by overriding the view OnAppearing() and manually changing the info you want, without recreating the view itself.
@AlisonFernandes could you point me to example with bindable properties without xaml? Thank you.
public class FooPage : ContentPage
BindingContext = new MyViewModel();
var mainStack = new StackLayout();
var textEntry = new Entry()
Placeholder = "some text"
textEntry.SetBinding<MyViewModel>(Entry.TextProperty, model => model.SomeTextProperty, BindingMode.TwoWay );
var myButton = new Button()
Text = "Login"
myButton.SetBinding<MyViewModel>(Button.CommandProperty, model => model.BarCommand);
Content = mainStack;
BindingContext = this;
locationLabel.SetBinding<MainPage> (Label.TextProperty, model => model.LocationLabel);
LocationLabel = "Location";
@AlisonFernandes This does not set my label text. The code is located in my MainPage class.
@HristoEnev you're snippet is too short and lacks some useful information but, from what I can see, you're making a circular reference that doesn't implement all of the required functionality, more specifically, the bindable properties. Provided your LocationLabel is a String property and your locationLabel is a Label (please, for the anyone involved insanity sake, improve your variables names ), your LocationLabel should implement the INotifyPropertyChanged functionality, so it has a way to inform the binding system something has changed. This will require you to implement INotifyPropertyChanged or use a framework like MvvmLight or MvvmCross that already does that, thus, you shouldn't bind your View to itself, the View and ViewModel should be decoupled.
You can read more about data binding here, just skip the XAML part, you should implement something similar to the C# code in there.
Thank you very much for your help @AlisonFernandes . You were very helpful! Much appreciated
Thank you very much for your help @AlisonFernandes .
You can pass your current page's view model to your new pop up screen through constructor and just change the view model which will help you reflect in the previous page and you can just close your pop up using PopAsync.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies