在WPF中如何定义一个数据模板在枚举的情况下? [英] In WPF how to define a Data template in case of enum?
问题描述
我有一个定义为类型的枚举
I have a Enum defined as Type
public Enum **Type**
{
OneType,
TwoType,
ThreeType
};
现在我将类型绑定到下拉功能区控件下拉菜单一个功能区控件,显示带有相应图像的MenuName的每个菜单。
Now I bind Type to a drop down Ribbon Control Drop Down Menu in a Ribbon Control that displays each menu with a MenuName with corresponding Image.
(我正在使用Syncfusion功能区控件)。
( I am using Syncfusion Ribbon Control ).
我希望每个枚举类型(OneType)数据模板被定义为具有菜单名称和corrospending图像。
I want that each enum type like ( OneType ) has data template defined that has Name of the menu and corrospending image.
如何定义枚举的数据模板?
How can I define the data template of enum ?
请给我解决方案,如果可能的话!
Please suggest me the solution, if this is possible !!
请告诉我,如果不可能,或者我在错误的方向思考! p>
Please also tell me if its not possible or I am thinking in the wrong direction !!
推荐答案
一种方法是创建一个 DataTemplateSelector
,并将其分配给 ItemTemplateSelector
菜单的属性。在 DataTemplateSelector
的代码中,您只需要根据枚举值
One way to do it would be to create a DataTemplateSelector
, and assign it to the ItemTemplateSelector
property of the menu. In the code of the DataTemplateSelector
, you just need to return a DataTemplate
based on the enum value
这篇关于在WPF中如何定义一个数据模板在枚举的情况下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!