Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind to property in a nested static class

Tags:

c#

.net

binding

wpf

I have the following construction:

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}}" />

(where ns points to the assembly and namespace where "Constants" is defined).
This results in two errors:

  • "Cannot find the type 'Constants.Foo'. Note that type names are case sensitive."
  • "Type 'ns:Constants.Foo' was not found."

I also tried:

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

This results in one error:

  • "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?

like image 579
Jan Willem B Avatar asked Jun 19 '12 08:06

Jan Willem B


1 Answers

this works for me

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

local is

 xmlns:local="clr-namespace:WpfTestApp1"
like image 64
blindmeis Avatar answered Oct 01 '22 06:10

blindmeis