簡體   English   中英

綁定到嵌套靜態類中的屬性

[英]Bind to property in a nested static class

我有以下結構:

public static class Constants {
  public static class Foo {
    public static string Bar {
      get {
        //Constants.Foo.Bar == "FooBar"
        return "FooBar";
      }
    }
  }
}

我想將它綁定到usercontrol中的按鈕。

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

(其中ns指向定義“常量”的程序集和命名空間)。
這導致兩個錯誤:

  • “找不到類型'Constants.Foo'。請注意,類型名稱區分大小寫。”
  • “未找到類型'ns:Constants.Foo'。”

我也嘗試過:

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

這導致一個錯誤:

  • “未找到類型'ns:常量+ Foo'。”

是否可以綁定到靜態類中的靜態類中的靜態屬性? 如果有,怎么樣?

這對我有用

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

當地是

 xmlns:local="clr-namespace:WpfTestApp1"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM