Binding a constant to a radiobutton IsChecked commandparameter
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.
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}}
精彩评论