StaticExtension value cannot be resolved

WpfXamlData BindingStaticXamlparseexception

Wpf Problem Overview


I'm facing some issues with a WPF binding to a static property. In my application there is a class called Globals which contains a static property to ThisAddIn. This object allows me to access a User property which basically is what I want to use in my Binding. So, my XAML looks like this:

<TextBlock Text="{Binding Path=User.Name
                   , Source={x:Static Member=s:Globals.ThisAddIn}}" />

The namespace s is declared at the top by the following line:

xmlns:s="clr-namespace:ConsoleApplication16.Model"

I found a ton of different approaches of how to refer to the static Property in XAML, but none of them worked except for this one, which also seems the most logical for me. Some samples I found, did not use Path or Member at all.

After some testing I found the right way to do this, is using "x:Static Member" to define the class and the static property you want to use, while Path defines the correct Properties inside this object, just like a normal binding would do.

Although this solution compiles without any complains, a XAMLParseException pops up directly telling me that the StaticExtension value cannot be resolved to an enumeration, static field, or static property.

Wpf Solutions


Solution 1 - Wpf

Ensure Globals.ThisAddIn is public.

You may also get this if you are using a resource file in which case you also need to ensure the access modifier is set to Public:

enter image description here

Solution 2 - Wpf

In output library project, you should ensure that the Resources.resx file's generator has been modified as PublicResXFileCodeGenerator instead of ResXFileGodeGenerator by default.

Replace following with...

Not public resource

This one

correct public resource

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRoperView Question on Stackoverflow
Solution 1 - WpfChuck RostanceView Answer on Stackoverflow
Solution 2 - WpfDennis ZhangView Answer on Stackoverflow