How to associate with enumeration in WPF with the "current" value

I have a simple .Net enum. I also have a view model object that has a "CurrentValue" property like my enumeration. This property can be data bound (the object implements INotifyPropertyChanged). Now I would like to show one user interface element for each enumeration value in a specific order and highlight the selection "CurrentValue" (in bold). I would like the declaration to be something like:

<StackPanel Orientation="Vertical">               
    <ContentControl Content="{x:Static MyEnum.Value1}" />
    <ContentControl Content="{x:Static MyEnum.Value2}" Margin="10" />
    <ContentControl Content="{x:Static MyEnum.Value3}" />
</StackPanel>

I would like to declare each value separately to indicate the order, but also because I want some elements to have certain margin values. In addition, I will want to display specific icons for each value later.

Now I have lost how I can declare that I want the control associated with CurrentValue to be bold. I tried using the generic DataTrigger template inside the template to check the contents on CurrentValue, but it seems the trigger value cannot be a binding.

I also thought that you were going to disable the ListBox, but then I cannot have specific fields for certain elements. Or can I?

+3
source share
1 answer

Try this for size ...

<ListBox>
  <ListBoxItem><local:MyEnum>Value1</local:MyEnum></ListBoxItem>
  <ListBoxItem Margin="10"><local:MyEnum>Value2</local:MyEnum></ListBoxItem>
  <ListBoxItem><local:MyEnum>Value3</local:MyEnum></ListBoxItem>
</ListBox>

You need to map localxmlns to your CLR namespace.

+1
source

Source: https://habr.com/ru/post/1704045/


All Articles