wpfdata-bindingproperties.settings

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 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?


Solution

  • 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.