XTOOLKIT
XTOOLKIT
Collection of utilities, helper classes and WPF controls

Creating the Enum Bound ComboBox in WPF using xToolkit


This WPF control allows binding the fields of the flag enumeration to the multi-selection combo box.

Enumeration bound to combo box items
Enumeration bound to combo box items

Create flag enumeration with fields to be bound to the combo box

[Flags]
public enum EnumSample_e
{
    None = 0,
    Field1 = 1,
    Field2 = 2,
    Field3 = 4,
    Field2AndField3 = Field2 | Field3,
    Field4 = 8
}

Bind the View Model property in the XAML to the Value dependency property.

public class EnumComboBoxControlVM
{
    public EnumSample_e EnumPrp { get; set; }
}

<UserControl x:Class="Wpf.Docs.EnumComboBoxControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:ctrls="clr-namespace:Xarial.XToolkit.Wpf.Controls;assembly=Xarial.XToolkit.Wpf">
    <Grid>
        <ctrls:EnumComboBox Value="{Binding Path=EnumPrp}"/>
    </Grid>
</UserControl>

Control supports joined values as well as none (0) value. These items will be assigned with blue and gray colors correspondingly.


Powered by Docify