Localization in WPF MVVM
-
Hi , I need to change culture mainly between two languages ; italian and English using the Combobox in WPF MVVM. I tried to databind the ViewModel with my Mainview but I didn't succeed. I will be so thankful if someone could help. Here is my Combobox declaration in xaml :
<ComboBox IsEditable="True" Text="Language" HorizontalAlignment="Right" VerticalAlignment="Top" Width="95" Margin="34,21,34,0" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="#FF434C64" removed="Green" Height="24.96" />
Here is View Model definition :
public void ChangeLanguage()
{
if (SelectedLanguage == "en")
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");} else if (SelectedLanguage == "it-IT") { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT"); } }
Here the declaration within the construcor of my View Model
public ViewModel()
{LoadData(); ChangeLanguage(); Login = new DelegateCommand(this.Logging, delegate() { return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email)); }); Register = new DelegateCommand(this.Registering, delegate() { return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email)); });
-
Hi , I need to change culture mainly between two languages ; italian and English using the Combobox in WPF MVVM. I tried to databind the ViewModel with my Mainview but I didn't succeed. I will be so thankful if someone could help. Here is my Combobox declaration in xaml :
<ComboBox IsEditable="True" Text="Language" HorizontalAlignment="Right" VerticalAlignment="Top" Width="95" Margin="34,21,34,0" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="#FF434C64" removed="Green" Height="24.96" />
Here is View Model definition :
public void ChangeLanguage()
{
if (SelectedLanguage == "en")
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");} else if (SelectedLanguage == "it-IT") { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT"); } }
Here the declaration within the construcor of my View Model
public ViewModel()
{LoadData(); ChangeLanguage(); Login = new DelegateCommand(this.Logging, delegate() { return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email)); }); Register = new DelegateCommand(this.Registering, delegate() { return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email)); });
Where is your
SelectedLanguage
property declaration? What does it look like?