绑定到嵌套静态类中的属性

编程入门 行业动态 更新时间:2024-10-23 01:45:34
本文介绍了绑定到嵌套静态类中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的结构如下:

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."
    • 我也尝试过:

      <Button Content="{Binding Source={x:Static ns:Constants+Foo.Bar}}" />

      这会导致一个错误:

      • 未找到类型'ns:Constants + Foo'."
        • "Type 'ns:Constants+Foo' was not found."
        • 是否可以绑定到静态类中的静态类中的静态属性?如果是,怎么办?

          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"

更多推荐

绑定到嵌套静态类中的属性

本文发布于:2023-11-12 12:31:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581505.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   绑定   静态   类中   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!