Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A pretty easy way to do this is to use an ObjectDataProvider</p> <pre><code>&lt;ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="DetailScopeDataProvider"&gt; &lt;ObjectDataProvider.MethodParameters&gt; &lt;x:Type TypeName="local:DetailScope" /&gt; &lt;/ObjectDataProvider.MethodParameters&gt; &lt;/ObjectDataProvider&gt; </code></pre> <p>Use the ObjectDataProvider as the ItemsSource for the ComboBox, bind SelectedItem to the Scope property and apply a converter for the display of each ComboBoxItem</p> <pre><code>&lt;ComboBox Name="ScopeComboBox" ItemsSource="{Binding Source={StaticResource DetailScopeDataProvider}}" SelectedItem="{Binding Scope}" Width="120" Height="23" Margin="12"&gt; &lt;ComboBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Converter={StaticResource CamelCaseConverter}}"/&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.ItemTemplate&gt; &lt;/ComboBox&gt; </code></pre> <p>And in the converter you can use Regex for CamelCase string splitter found in <a href="https://stackoverflow.com/questions/155303/net-how-can-you-split-a-caps-delimited-string-into-an-array">this</a> question. I used the most advanced version but you can probably use a simplier one. OtherDetail + the regex = Other Detail. Making return value lower and then return a string with first Character UpperCase should give you expected result</p> <pre><code>public class CamelCaseConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string enumString = value.ToString(); string camelCaseString = Regex.Replace(enumString, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ").ToLower(); return char.ToUpper(camelCaseString[0]) + camelCaseString.Substring(1); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload