Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
};

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

like image 232
Ashish Ashu Avatar asked Nov 28 '22 15:11

Ashish Ashu


1 Answers

Not sure whether this is an applicable solution to your particular situation, but it is relevant to the question of DataTemplate for enum. It is possible to create one DataTemplate for the enum type and use DataTriggers to tweak the controls in that template for individual enum value:

Enum:

enum MyEnumType 
{
    ValueOne,
    ValueTwo,
}

Template:

<DataTemplate DataType="{x:Type MyEnumType}">
    <TextBlock x:Name="valueText"/>
    <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding}" Value="{x:Static MyEnumType.ValueOne}">
            <Setter TargetName="valueText" Property="Text" Value="First Value" />
        </DataTrigger>
        <DataTrigger Binding="{Binding}" Value="{x:Static MyEnumType.ValueTwo}">
            <Setter TargetName="valueText" Property="Text" Value="Second Value" />
        </DataTrigger>
    </DataTemplate.Triggers>
</DataTemplate>
like image 126
alexei Avatar answered Dec 06 '22 20:12

alexei