具有 Enum 类型属性的 WPF 用户控件 [英] WPF user control with a property of type Enum
问题描述
我有一个 UserControl
叫做 InputSensitiveTextBox
,它继承自 TextBox
.它有一个我定义的名为 CurrentInputType
的属性,它的类型为 MyControlsNamespace.SupportedInputTypes
(值为 Keyboard
、Mouse
、触摸板
、VirtualKey
).我需要在 Xaml 中设置此属性,就像我可能设置 HorizontalAlignment
或 ScrollbarVisibility
一样:
I have a UserControl
called InputSensitiveTextBox
that inherits from TextBox
. It has a property I define called CurrentInputType
, which is of type MyControlsNamespace.SupportedInputTypes
(with values Keyboard
, Mouse
, Touchpad
, VirtualKey
). I need to have this property be set in Xaml just like I might set HorizontalAlignment
or ScrollbarVisibility
as such:
MyControlsNamespace.InputSensitiveTextBox Background="Black" CurrentInputType="Keyboard"
请指教:)
推荐答案
您需要使用 Static
标记扩展来引用您在 xaml 中的枚举,并且您还需要将其命名空间添加到您的命名空间声明中.
You need to use the Static
markup extension to reference your enumeration in xaml and you also need to add its namespace to your namespace declarations.
xmlns:MyControlsNamespace ="clr-namespace:MyControlsNamespace"
<MyControlsNamespace:InputSensitiveTextBox
CurrentInputType="{x:Static MyControlsNamespace:SupportedInputTypes.Keyboard}"
/>
这篇关于具有 Enum 类型属性的 WPF 用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!