Reputation: 71
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:
Any help is very appreciated. Thank you, guys.
Upvotes: 0
Views: 703
Reputation: 5366
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; }
}
Upvotes: 0