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

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

问题描述

在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}

因此​​,这里是最后的结果code:

So here is the final result code:

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

来源:<一个href=\"http://weblogs.asp.net/thomaslebrun/archive/2009/03/26/wpf-how-to-bind-a-control-to-a-property-defined-in-the-settings.aspx\">WPF - 如何将控件绑定到在设置中定义的属性

注:由​​于@Daniel和@nabulke指出,不要忘记将访问修饰符您的设置文件公开范围用户

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天全站免登陆