Note that there are some explanatory texts on larger screens.

plurals
  1. POWays to bind Enums to WPF controls like Combobox, TabHeader etc
    primarykey
    data
    text
    <p>In my program (MVVM WPF) there are lot of Enumerations, I am binding the enums to my controls in the view.</p> <p>There are lot of ways to do it.</p> <p>1) To bind to ComboBoxEdit(Devexpress Control). I am using ObjectDataProvider.</p> <p>and then this </p> <pre><code>&lt;dxe:ComboBoxEdit ItemsSource="{Binding Source={StaticResource SomeEnumValues}&gt; </code></pre> <p>This works fine but in TabControl header it doesn't. </p> <p>2) So, I thought of using IValueConverter that didnt worked either.</p> <pre><code>public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is Model.MyEnum)) { return null; } Model.MyEnum me = (Model.MyEnum)value; return me.GetHashCode(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } </code></pre> <p>on XAML:</p> <pre><code>&lt;local:DataConverter x:Key="myConverter"/&gt; &lt;TabControl SelectedIndex="{Binding Path=SelectedFeeType, Converter={StaticResource myConverter}}"/&gt; </code></pre> <p>3) The third way of doing this is to make a behavior dependency property</p> <p>Something like this </p> <pre><code>public class ComboBoxEnumerationExtension : ComboBox { public static readonly DependencyProperty SelectedEnumerationProperty = DependencyProperty.Register("SelectedEnumeration", typeof(object), typeof(ComboBoxEnumerationExtension)); public object SelectedEnumeration { get { return (object)GetValue(SelectedEnumerationProperty); } set { SetValue(SelectedEnumerationProperty, value); } } </code></pre> <p>I want to know what is the best way to handle enumerations and binding to it. Right now I am not able to bind tabheader to the enums.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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