views:

97

answers:

2

I have a Enum defined as Type

public Enum **Type**
{
   OneType,
   TwoType,
   ThreeType
};

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.

( I am using Syncfusion Ribbon Control ).

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

Please also tell me if its not possible or I am thinking in the wrong direction !!

+4  A: 

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

Thomas Levesque
Thanks Thomas for the reply. I have seen the DataTemplateSelector and ItemTemplateSelector links and it seem to me that its possible.Just to ask you if you have tried this similar thing , it will be great if you can provide me the snippets of that!!
Ashish Ashu
there's an example on the MSDN page
Thomas Levesque
+1  A: 

It's very often the case that people use enums when they should be using polymorphism. You should, at the least, check to see if this is one of those cases. The presence of switch blocks in your class's code that check the value of the instance's enum is often a sign that this is a good idea. If you can eliminate the enum by defining subclasses, then you don't have to mess around with the likes of data template selectors and value converters.

Robert Rossney