Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Checkbox in a combobox?

$
0
0

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>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>