无法在WPF中找到静态引用的枚举类型 [英] Unable to find enum type for static reference in WPF
问题描述
我试图将一个枚举绑定到WPF中的单选按钮(灵感来自这个答案),但是我找不到转换器参数的枚举类型:
I'm trying to bind an enum to a radio button in WPF (Inspired by this answer), but I have trouble finding the enum type for the converter parameter:
枚举在以下方式
namespace Application.Models
{
public class Enums
{
public enum MySelections { one, two ,three };
public MySelections CurrentSelection;
...
}
}
$ b $我试图绑定这样的复选框(数据上下文被认为是正确的,并实现了价值转换器)。
I am trying to bind now the checkbox like this (The data context is assumed to be correct and the value converter implemented:)
<Window x:Class="Application.MainWindow"
....
xnlns:models="clr-namespace:Application.Models" >
...
<RadioButton Content="One"
IsChecked="{Binding Path=CurrentSelection, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static models:Enums.MySelections.one}}" />
...
问题在于 {x:Static型号:Enums.MySelections.one}
不断抛出错误,类型型号:Enums.MySelections
找不到。
The problem lies with {x:Static models:Enums.MySelections.one}
which constantly throws the error that the type models:Enums.MySelections
could not be found.
如何找到我的枚举类型?
How can I find my enum type?
推荐答案
您可以将其声明为你的课程:
You could declare it outside of your class:
namespace Application.Models
{
public enum MySelections { one, two, three };
public class Enums
{
public MySelections CurrentSelection;
然后这个xaml将工作:
And then this xaml will work:
.... ConverterParameter={x:Static models:MySelections.one}
x:static
标记具有固定的语法:
The x:Static
markup has the fixed syntax:
{x:静态
前缀:typeName.staticMemberName}
{x:Static prefix:typeName.staticMemberName}
这篇关于无法在WPF中找到静态引用的枚举类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!