Intro: Here is a part of my Translator that I use in my app. I want to update all the strings in it when I change the language with a ComboBox.
Problem: I would like to update labels Content when my Converters Property gets changed. Is it possible? This way (how I made it) doesn't update Content if I change CurrentLanguage.
<Label
ID:Name="CompanyName"
Content="{Binding ElementName=CompanyName, Path=Name, Converter={ID:Static Controller:Translator.Instance}}" />
This ComboBox changes my Current value - works
<ComboBox
SelectedItem="{Binding Path=CurrentLanguage, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource FlagConverter}}">
Translator code behind - works (PropertyChanged gets fired)
public partial class Translator : IValueConverter, INotifyPropertyChanged
{
...
private String m_currentLanguage;
public String CurrentLanguage
{
get { return m_currentLanguage; }
set
{
m_currentLanguage = value;
OnPropertyChanged("CurrentLanguage");
}
}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Get((String)value); // nonrelevant function - works
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return GetOriginal((String)value); // nonrelevant function - works
}
#region Events
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}