开发者

Is it possible to bind to a value in Properties.Settings.Default?

Is it possible to bind to a value in Properties.Settings.Default in a way that will keep my UI current with the value stored there?

I have a class:

public class FavoritePlayer
{
    public string Name
    {
        get
        {
            return wpfSample021.Properties.Settings.Default.FavoritePlayer.ToString();
        }
        set
        {
            wpfSample021.Properties.Settings.Default.FavoritePlayer = value;
        }
    }
}

In my XAML, I have a resource:

    <local:FavoritePlayer x:Key="fvPlayer"/>

and a binding:

    <Label DataContext="{DynamicResource fvPlayer}" Content="{Binding 开发者_StackOverflow社区Path=Name}"/>

What I would like is for the data-binding to update any time the property is changed. Is there a way to do this?


Conveniently for you, ApplicationSettingsBase implements INotifyPropertyChanged so you just need to subscribe to PropertyChanged on Properties.Settings.Default and raise your own PropertyChanged in response.


You need your properties to implement INotifyPropertyChanged in order for bindings to recognise when the property value changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜