11

私は次の構造を持っています:

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

これをユーザーコントロールのボタンにバインドしたい。

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

(ns は、"定数" が定義されているアセンブリと名前空間を指します)。
これにより、次の 2 つのエラーが発生します。

  • 「型 'Constants.Foo' が見つかりません。型名は大文字と小文字が区別されることに注意してください。」
  • 「タイプ 'ns:Constants.Foo' が見つかりませんでした。」

私も試しました:

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

これにより、1 つのエラーが発生します。

  • 「タイプ 'ns:Constants+Foo' が見つかりませんでした。」

静的クラスの静的クラスの静的プロパティにバインドすることは可能ですか? はいの場合、どのように?

4

1 に答える 1

16

これは私のために働く

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

ローカルは

 xmlns:local="clr-namespace:WpfTestApp1"
于 2012-06-19T09:25:21.883 に答える