Bind to a property in a nested static class

I have the following construct:

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 usercontrol.

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

(where ns refers to the assembly and namespace where "Constants" is defined).
This leads to two errors:

  • "Cannot find type 'Constants.Foo. Please note that type names are case sensitive."
  • 'Type' ns: Constants.Foo 'not found.

I also tried:

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

This leads to one error:

  • "Type 'ns: Constants + Foo' not found."

Is it possible to bind a static property in a static class in a static class? If so, how?

+6
source share
1 answer

it works for me

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

local

  xmlns:local="clr-namespace:WpfTestApp1" 
+8
source

Source: https://habr.com/ru/post/918448/


All Articles