Given the following ViewModel ...
public class NameEntryViewModel
{
public NameEntryViewModel()
{
Branding = new Dictionary<string, string>();
Branding.Add("HeaderLabelText", "Welcome to the app");
}
public Dictionary<string, string> Branding { get; set; }
}
Linked to page ...
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Monaco.Forms.Views.NameEntryPage">
<Label Text="{Binding Branding[HeaderLabelText]}" />
</ContentPage>
When the page appears, Label will receive the text "Welcome to the app." This works great and fits into our plan to configure and globalize our application. Then, in this example, the static branding dictionary is staticized, but in the real world it is initialized with data from a service call.
However, if the user wants to switch the language to Spanish, we need each associated label to be updated to a new value. It's easy enough to reset the branding dictionary and populate it with Spanish translations, but how can we get the controls to be updated from related sources?
b/c, , backing Text . , .
ANSWER
, . , , , , . MVVMCross, ...
public MvxCommand CultureCommand
{
get
{
return new MvxCommand(async () =>
{
_brandingService.ToggleCurrentCulture();
await ApplyBranding();
RaisePropertyChanged(() => Branding);
});
}
}