简体   繁体   中英

Extended WPF Toolkit CheckComboBox Style in ToolBar

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 focused style:

在此处输入图片说明

Any help is very appreciated. Thank you, guys.

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; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM