6

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
  • 1,201
  • 2
  • 10
  • 21
  • style the combo box item for your desired template. – pushpraj Aug 06 '14 at 10:18
  • Maybe helps someone in future Multi select combobox http://stackoverflow.com/questions/27753790/how-to-prevent-a-combobox-from-closing-after-a-selection-is-clicked – Heena Jan 05 '15 at 13:13
  • 1
    If you're developing a Visual Studio plug in, you can use this: **Microsoft.VisualStudio.Diagnostics.UI.Controls.MultiSelectComboBox** (Assembly: Microsoft.VisualStudio.Diagnostics.Common.dll) – Shakaron Aug 24 '15 at 16:57

1 Answers1

6

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

pushpraj
  • 13,458
  • 3
  • 33
  • 50
  • 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. – DT sawant Aug 06 '14 at 10:34
  • 1
    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. – pushpraj Aug 06 '14 at 11:07
  • How can I reuse this control?I want to create custom user control which can be reused later on. – DT sawant Aug 06 '14 at 11:24
  • You may probably list down the most significant features/behavior let's try to wrap this in a custom control. – pushpraj Aug 06 '14 at 11:39
  • 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. – DT sawant Aug 06 '14 at 11:46
  • 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? – pushpraj Aug 06 '14 at 11:56
  • That's right.We need to derive control from combobox. – DT sawant Aug 06 '14 at 12:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58777/discussion-between-pushpraj-and-dt-sawant). – pushpraj Aug 06 '14 at 12:01