Multi select combobox with checkbox generic control in wpf

[亡魂溺海] 提交于 2019-12-22 05:19:09

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/25157744/multi-select-combobox-with-checkbox-generic-control-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!