如何添加具有一组离散字符串值的依赖属性?
标准 WPF 元素中的许多属性支持一小组离散值,在 XAML 中创建元素时可以将这些值指定为字符串。例如,StackPanel 的 Orientation 属性支持“水平”和“垂直”作为离散属性。在打开“方向”属性的报价后,IntelliSense 会通过为您提供这两个选项来帮助您。我知道值转换器涉及将这些值转换为 System.Windows.Controls.Orientation 枚举类型的枚举值。
如何为自定义控件的自定义依赖属性执行此操作?我希望它能够像使用 IntelliSense 帮助等标准元素依赖属性一样工作。
谢谢
Many properties in standard WPF elements support a small discrete set of values that can be specified as strings when the elements are created in XAML. For example, StackPanel's Orientation property supports "Horizontal" and "Vertical" as discrete properties. IntelliSense aids you by giving you these two options after you open the quotes for the Orientation property. I know a value converter is involved in converting these to enum values of type System.Windows.Controls.Orientation enum.
How do you do this for a custom dependency property for your custom control? I want it to work just as it does for standard element dependency properties with the IntelliSense help and all.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它们在运行时不会改变,则答案是
enum
。如果它们确实发生变化,我的方法是使用字符串(或实现 ToString() 的对象)和填充可能值的转换器。顺便说一句,这与普通 WinForms 属性网格的工作方式相同。
If they won't change at run time, the answer is
enum
. If they do change, the way I do them is with strings (or objects that implementToString()
) and converters that fill in the possible values.Incidentally this is the same way the normal WinForms property grid works.