是否可以绑定到Properties.Settings.Default中的值?

时间:2011-05-02 19:00:52

标签: wpf data-binding properties.settings

是否可以以一种方式绑定到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}"/>

我想要的是数据绑定在属性更改时更新。有没有办法做到这一点?

2 个答案:

答案 0 :(得分:4)

方便地为您ApplicationSettingsBase实施INotifyPropertyChanged,因此您只需在PropertyChanged订阅Properties.Settings.Default并自行提出PropertyChanged作为回应。

答案 1 :(得分:0)

您需要使用属性来实现INotifyPropertyChanged,以便绑定能够识别属性值何时发生更改。