是否可以绑定到Properties.Settings.Default中的值? [英] Is it possible to bind to a value in Properties.Settings.Default?

查看:374
本文介绍了是否可以绑定到Properties.Settings.Default中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以绑定到Properties.Settings.Default中的一个值,以保持我的UI保存在那里的值?

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?

我有一个类:

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

在我的XAML中,我有一个资源:

In my XAML, I have a resource:

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

和绑定:

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

推荐答案

方便地为您, ApplicationSettingsBase 实现 INotifyPropertyChanged ,所以你只需要订阅 PropertyChanged Properties.Settings.Default 并提出自己的 PropertyChanged 作为回应。

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.

这篇关于是否可以绑定到Properties.Settings.Default中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆