Extended WPF Toolkit CheckComboBox Style in ToolBar

679 views Asked by At

I placed xctk CheckComboBox into a ToolBar. I have a simple ComboBox next to it and those two look different. The simple ComboBox has a style of ToolBar.ComboBoxStyleKey (https://msdn.microsoft.com/en-us/library/system.windows.controls.toolbar.comboboxstylekey(v=vs.110).aspx). But it's not applicable to CheckComboBox.

Is it simplier to derive my own CheckComboBox from ComboBox (and have the same style then), or to change style of the CheckComboBox?

How can I change the look so that the CheckComboBox looks like the ComboBox?

On the left, there is the ComboBox, on the right, there is a CheckComboBox:

  • This is normal visual style:

This is normal visual style

  • This is focused style:

enter image description here

Any help is very appreciated. Thank you, guys.

1

There are 1 answers

2
Ayyappan Subramanian On

You can easily create a checkboxcombo using ItemTemplate. Refer below code.

<Grid>
    <StackPanel>
        <ComboBox x:Name="cbo">
            <ComboBox.ItemTemplate>
                <DataTemplate DataType="local:MyCombo">
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding IsChecked}"/>
                        <TextBlock Text="{Binding Name}"/>
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </StackPanel>
</Grid>

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        List<MyCombo> lst = new List<MyCombo>();
        for (int i = 0; i < 10; i++)
        {
            lst.Add(new MyCombo() {IsChecked = true,Name = "Name"+i});
        }
        cbo.ItemsSource = lst;
    }
}

public class MyCombo
{
    public bool IsChecked { get; set; }

    public string Name { get; set; }
}