Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: Property Grid: Displaying enums in combobox

$
0
0
Thank you Boucher!

I had two issues with the provided code:
1.) For some reason, when we specify the combobox explicitly (inside the EditorTemplateDefinition) it wasn't pickup up our default style. I'm not sure if this is how the propertygrid works, or if it was due to a modification that we made locally. Anyway, I added a new style which based itself on our default combobox style so that we could call the style explicitly.

<Style x:Key="PropertyGridComboStyle" TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}"/>

2.) The next issue was that I needed a way to localize the strings. I wasn't able to do it using the xaml Array (shown above). Perhaps there is a way, but I couldn't find it. So, I defined my combobox now like this:

<xctk:EditorTemplateDefinition >
<xctk:EditorTemplateDefinition.TargetProperties>
              <sys:String>SomeOption</sys:String>
            </xctk:EditorTemplateDefinition.TargetProperties>
            <xctk:EditorTemplateDefinition.EditingTemplate >
              <DataTemplate>
                <ComboBox  SelectedIndex="{Binding Value, Converter={converters:MyEnumToIntConverter}}" Style ="{DynamicResource PropertyGridComboStyle}">
                  <ComboBoxItem Content="{x:Static properties:Resources.MyLocalizedOption1}"/>
                  <ComboBoxItem Content="{x:Static properties:Resources.MyLocalizedOption2}"/>
                </ComboBox>
              </DataTemplate>
            </xctk:EditorTemplateDefinition.EditingTemplate>
          </xctk:EditorTemplateDefinition>
3.) Finally, I provided a converter to convert from my enum to an index.

Thank you very much for your help!
 -Glenn

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>