I am trying to change my combobox to include a checkbox in front of every item. everything works fine until I wanted to set the displaymemberpath and selectedvaluepath. The error is:
'System.Windows.HierarchicalDataTemplate' value cannot be assigned to property 'ItemTemplate' of object 'System.Windows.Controls.ComboBox'. Cannot set both DisplayMemberPath and ItemTemplate.
Here is part of my xaml: The combobox binding to an observablecollection of myObject, myObject has 3 properties Key, Name and IsSelected signal if the checkbox is checked.
Please see the <CheckBox Content="{Binding Path=Name}". I am thinking the checkbox content should bind to the DisplayMemberPath instead hardcode name. Or that's just not possible as the above error pointed out?
<ComboBox
x:Name="cboCore"
SnapsToDevicePixels="True"
OverridesDefaultStyle="True"
MinWidth="120"
MinHeight="20"
ItemsSource="{Binding}"
DisplayMemberPath="Name"
SelectedValuePath="Key"
>
<ComboBox.ItemTemplate>
<HierarchicalDataTemplate>
<CheckBox Content="{Binding Path=Name}"
IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
Click="CheckBox_Click"
/>
</HierarchicalDataTemplate>
</ComboBox.ItemTemplate>