本文介绍了绑定到嵌套静态类中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的结构如下:
public static class Constants { public static class Foo { public static string Bar { get { //Constants.Foo.Bar == "FooBar" return "FooBar"; } } } }我想将此绑定到用户控件中的按钮上.
I want to bind this to a button in a usercontrol.
<Button Content="{Binding Source={x:Static ns:Constants.Foo.Bar}}" />(其中ns指向定义常量"的程序集和名称空间). 这导致两个错误:
(where ns points to the assembly and namespace where "Constants" is defined). This results in two errors:
- 找不到类型'Constants.Foo'.请注意,类型名称区分大小写."
- 未找到类型'ns:Constants.Foo'."
- "Cannot find the type 'Constants.Foo'. Note that type names are case sensitive."
- "Type 'ns:Constants.Foo' was not found."
- 未找到类型'ns:Constants + Foo'."
- "Type 'ns:Constants+Foo' was not found."
我也尝试过:
<Button Content="{Binding Source={x:Static ns:Constants+Foo.Bar}}" />这会导致一个错误:
是否可以绑定到静态类中的静态类中的静态属性?如果是,怎么办?
Is is possible to bind to a static property in a static class in a static class? If yes, how?
推荐答案这对我有用
<Button Content="{Binding Source={x:Static local:Constants+Foo.Bar}}" />本地为
xmlns:local="clr-namespace:WpfTestApp1"更多推荐
绑定到嵌套静态类中的属性
发布评论