绑定到设置中定义的值 [英] Bind to a value defined in the Settings

查看:34
本文介绍了绑定到设置中定义的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WPF 中,我可以将绑定与设置中定义的值结合使用吗?如果可能,请提供样本.

In WPF, Can I use binding with values defined in Settings? If this is possible, please provide a sample.

推荐答案

首先,您需要添加一个自定义 XML 命名空间,用于设计定义设置的命名空间:

First, you need to add a custom XML namespace that will design the namespace where the settings are defined:

xmlns:properties="clr-namespace:TestSettings.Properties"

然后,在您的 XAML 文件中,使用以下语法访问默认设置实例:

Then, in your XAML file, access the default settings instance using the following syntax:

{x:Static properties:Settings.Default}

这里是最终结果代码:

<ListBox x:Name="lb"
         ItemsSource="{Binding Source={x:Static properties:Settings.Default},
                               Path=Names}" />

来源:WPF - 如何将控件绑定到设置中定义的属性?

注意:正如@Daniel 和@nabulke 所指出的,不要忘记将设置文件的Access Modifier 设置为Public范围User

Note: As pointed out by @Daniel and @nabulke, don't forget to set Access Modifier of your settings file to Public and Scope to User

这篇关于绑定到设置中定义的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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