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
Author by
DT sawant
Updated on June 17, 2022Comments
-
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 over 9 yearsthanks 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 over 9 yearsThis 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 over 9 yearsHow can I reuse this control?I want to create custom user control which can be reused later on.
-
pushpraj over 9 yearsYou may probably list down the most significant features/behavior let's try to wrap this in a custom control.
-
DT sawant over 9 yearscurrently 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 over 9 yearsA 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 over 9 yearsThat's right.We need to derive control from combobox.
-
pushpraj over 9 yearsLet us continue this discussion in chat.