是否可以以一种方式绑定到Properties.Settings.Default中的值,使我的UI保持当前存储的值?
我有一个班级:
public class FavoritePlayer
{
public string Name
{
get
{
return wpfSample021.Properties.Settings.Default.FavoritePlayer.ToString();
}
set
{
wpfSample021.Properties.Settings.Default.FavoritePlayer = value;
}
}
}
在我的XAML中,我有一个资源:
<local:FavoritePlayer x:Key="fvPlayer"/>
和绑定:
<Label DataContext="{DynamicResource fvPlayer}" Content="{Binding Path=Name}"/>
我想要的是数据绑定在属性更改时更新。有没有办法做到这一点?
答案 0 :(得分:4)
方便地为您ApplicationSettingsBase
实施INotifyPropertyChanged
,因此您只需在PropertyChanged
订阅Properties.Settings.Default
并自行提出PropertyChanged
作为回应。
答案 1 :(得分:0)
您需要使用属性来实现INotifyPropertyChanged
,以便绑定能够识别属性值何时发生更改。