具有 Enum 类型属性的 WPF 用户控件 [英] WPF user control with a property of type Enum

查看:44
本文介绍了具有 Enum 类型属性的 WPF 用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UserControl 叫做 InputSensitiveTextBox,它继承自 TextBox.它有一个我定义的名为 CurrentInputType 的属性,它的类型为 MyControlsNamespace.SupportedInputTypes(值为 KeyboardMouse触摸板VirtualKey).我需要在 Xaml 中设置此属性,就像我可能设置 Horizo​​ntalAlignmentScrollbarVisibility 一样:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆