无法在 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;
...
}
}
我现在正在尝试像这样绑定复选框(假设数据上下文是正确的并且实现了值转换器:)
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 models:Enums.MySelections.one}
上,它不断抛出无法找到类型 models: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?
推荐答案
使用+"代替."获取 XAML 中的嵌套类型:
Use "+" instead of "." to get to a nested type in XAML:
{x:Static models:Enums+MySelections.one}
这篇关于无法在 WPF 中找到静态引用的枚举类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!