0

In WPF I'm trying to bind to a property of a readonly field in a static class, I've already looked at this which will allow to bind to const string in a static class like this

<TextBlock Text="{x:Static A:MyConstants.SomeConstantString}" />

What I'm trying to do is like this

<TextBlock Text="{x:Static A:MyConstants.SomeReadOnlyField.StringProp}" />

but it gives me an error

Nested types are not supported

Community
  • 1
  • 1
Geiziry
  • 23
  • 5

2 Answers2

6

Provided that SomeReadOnlyField is a public static readonly field in class MyConstants, and that is has a public StringProp property, you could write your Binding like this:

Text="{Binding Path=StringProp
               Source={x:Static A:MyConstants.SomeReadOnlyField}}"

Note that while a Binding Path must resolve to the name of a public property, the x:Static markup extension used for the Binding Source can very well reference a static field.

Clemens
  • 123,504
  • 12
  • 155
  • 268
0

The error means you cannot use a path to a value (stringprop) that is a value of a complex type (the readonlyfield).

the prop as in your first example, should be a property of MyConstants