0

I am trying to do the same thing as it is done here:

Unable to find enum type for static reference in WPF

but instead of enums I have some string constants:

namespace MyProject.XYZ
{
     public class MyConstants
     {
          public const string AAA = "Type AAA";
          public const string BBB = "Type BBB";
          public const string CCC = "Type CCC";
          ...
     }
}

I have a couple of radio buttons that look like this:

...
xmlns:myConstants="clr-namespace:MyProject.XYZ"
...


<RadioButton IsChecked="{Binding Path=CurrentSelection, Converter={StaticResource MyConverter}, ConverterParameter={x:Static myConstants:MyConstants
.AAA}}" />
...

But i get an error in regards with the command parameter: 'myConstants:MyConstants.AAA' member is not valid because it does not have a qualifying type name.

I've done it with enums and it works, but the application that I am working on heavily relies on these constants.

Any ideas are greatly appreciated.

Thanks.

Community
  • 1
  • 1
asuciu
  • 1,234
  • 2
  • 21
  • 35

1 Answers1

1

This answer is a bit late but for somebody else could this be a usefull solution:

Define the class like this:

<Window.Resources>
  <local:MyConstants xmlns:local="clr-namespace:MyProject.XYZ" x:Key="MyConstants"/>
</Window.Resources>

And the Binding like this:

{Binding Path=CurrentSelection, Converter={StaticResource MyConverter}, ConverterParameter={StaticResource MyConstants}}
Silvermind
  • 5,791
  • 2
  • 24
  • 44