zv3*_*rk4 5 c# wpf xaml inotifypropertychanged ivalueconverter
简介: 这是我在应用程序中使用的翻译器的一部分。当我使用组合框更改语言时,我想更新其中的所有字符串。
问题: 当我的转换器属性发生更改时,我想更新标签内容。是否可以?如果我更改 CurrentLanguage,这种方式(我的制作方法)不会更新内容。
<Label
ID:Name="CompanyName"
Content="{Binding ElementName=CompanyName, Path=Name, Converter={ID:Static Controller:Translator.Instance}}" />
Run Code Online (Sandbox Code Playgroud)
这个组合框改变了我的当前值 -有效
<ComboBox
SelectedItem="{Binding Path=CurrentLanguage, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource FlagConverter}}">
Run Code Online (Sandbox Code Playgroud)
翻译器代码背后 -有效(PropertyChanged 被解雇)
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
}
Run Code Online (Sandbox Code Playgroud)
小智 2
我看到两种可能的解决方案:
| 归档时间: |
|
| 查看次数: |
7023 次 |
| 最近记录: |