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?
this works for me
<Button Content="{Binding Source={x:Static local:Constants+Foo.Bar}}" />
local is
xmlns:local="clr-namespace:WpfTestApp1"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.