wpf wpf中带有复选框通用控件的多选组合框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25157744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multi select combobox with checkbox generic control in wpf
提问by DT sawant
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.
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.
我发现这篇文章很有用,但我不能在每个应用程序中使用这个控件,因为 ItemsSource 类型可能会在每个应用程序中改变。我想创建通用控件,该控件将由可能具有不同 ItemsSource 的任何应用程序使用。如何创建可在任何应用程序中使用的通用控件?我想为此控件创建 DLL 并希望在所有应用程序中使用它。
回答by pushpraj
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
结果



