Multi select combobox with checkbox generic control in wpf

11,031

here is a sample for you

<ComboBox xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <ComboBox.Resources>
        <Style TargetType="ComboBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBoxItem">
                        <CheckBox>
                            <ContentPresenter />
                        </CheckBox>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ComboBox.Resources>
    <sys:String>item 1</sys:String>
    <sys:String>item 2</sys:String>
    <sys:String>item 3</sys:String>
    <sys:String>item 4</sys:String>
</ComboBox>

result

result

Share:
11,031
DT sawant
Author by

DT sawant

Updated on June 17, 2022

Comments

  • DT sawant
    DT sawant almost 2 years

    I want to create control which will allow user to select multiple selections from dropdown using check box.I have searched on Google and I got some links like

    http://code.msdn.microsoft.com/windowsapps/Multi-Select-ComboBox-in-cfbf1e22/view/SourceCode#content.

    I found this article useful but I can not use this control in every application because ItemsSource type may change in every application. I want to create generic control which will be used by any application which may have different ItemsSource. How do I create generic control which can be used in any application?I want to create DLL for this control and want to use it in all applications.

  • DT sawant
    DT sawant over 9 years
    thanks for your reply but I want to design control which will support binding and all other stuff which we can do in simple combobox.
  • pushpraj
    pushpraj over 9 years
    This is just an example how you can achieve the same. In the example you can remove the declared items and apply binding for ItemsSource, that will apparently apply check box to all the objects in the bound collection. The combo box in example fully support the binding, however check boxes may need additional code.
  • DT sawant
    DT sawant over 9 years
    How can I reuse this control?I want to create custom user control which can be reused later on.
  • pushpraj
    pushpraj over 9 years
    You may probably list down the most significant features/behavior let's try to wrap this in a custom control.
  • DT sawant
    DT sawant over 9 years
    currently user should be able to select multiple items that is only requirement.I know I will need to create dependency properties like itemssource,selectedItems and DisplayMemberpath etc but I am facing problems to make these properties generic.
  • pushpraj
    pushpraj over 9 years
    A ComboBox has most of those properties except SelectedItems, I think we can create a control derived from ComboBox and add the necessary properties and behavior. what do you think?
  • DT sawant
    DT sawant over 9 years
    That's right.We need to derive control from combobox.
  • pushpraj
    pushpraj over 9 years