views:

623

answers:

1

I have a simple .Net enum. I also have a view model object which has a "CurrentValue" property of the type of my enum. This property can be data-bound (the object implements INotifyPropertyChanged). Now I'd like to show one UI element for each value of the enum, in a specific order, and have the "CurrentValue" highlighted (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'd like to declare each value individually, to specify the order, but also because I want some of the elements to have specific margin values. Also, I will want to display specific icons for each value later on.

Now I'm lost as to how I can declare that I want the control associated with the CurrentValue to be bold. I tried using a generic DataTrigger inside a template to check the content against the CurrentValue, but it seems the Value of a trigger cannot be a binding.

I also considered going for a disabled ListBox, but then I can't have specific margins for specific items. Or can I?

A: 

Try this on 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'll need to map the local xmlns to your CLR namespace.

Drew Noakes
Hmm why didn't I think of that! Thanks!
No worries. I had to do something similar just a few days ago. But I didn't fully answer your question... have you managed to get the data context's enum value to be set in bold?
Drew Noakes
Not quite, will work on that later this week :) But I've found some resources on that already. Thanks again!