百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

Multiselect-ComboBox

> 编程语言
开源

多选组合框是一个具有多项选择功能的 WPF 自定义控件,还具有可自定义的功能,可对项目进行分组、排序和过滤。

199 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

多选组合框是一个具有多项选择功能的 WPF 自定义控件,还具有可自定义的功能,可对项目进行分组、排序和过滤。

Sdl.MultiSelectComboBox (WPF Custom Control)

Overview

The multi selection combo box is a WPF custom control with multiple item selection capabilities, along with customizable features to group, sort and filter items in the collection.

Components and Features

Selected Items Panel

The selected items are displayed like tags with a remove button They can be added or removed from the selected items collection, by selecting them from the items present in the Dropdown Menu list. Additionally, items can also be removed by interacting with them directly from the Selected Items Panel, as follows:

Device Action Description
Keyboard Backspace or Delete key If the Filter Criteria is empty, then the last item in the selected items collection is removed.
Mouse Remove Item Button The item is removed from the selected items collection

Visual States

The control has two visual states, Readonly and EditMode, which is identified by the IsEditMode property. When the control is in readonly mode, the items cannot be edited from the view. To switch to edit mode, select the control in the view or hit (F2) when the control has focus. Once the control is in edit mode, the items can be filtered, selected or removed. To switch back to readonly, move focus away from the control by selecting any other control in the view or by deactivating the parent window.

Visual state Description Example
Readonly The Dropdown Menu is collapsed and items present in the Selected Items Panel cannot be edited.
EditMode The Dropdown Menu can be expanded or collapsed when the button is clicked and items present in the Selected Items Panel can be edited.

Filter Criteria

When you type a character in the text area, the control applies a filter on the collection and suggests a list of items matching that criteria in the Dropdown Menu list. The developer can override the default filter service, based on their own business logic requirements, that implements IFilterService.

Depending on whether or not the ClearFilterOnDropdownClosing property is set to true and Dropdown Menu list as keyboard focus, the Filter Criteria is cleared automatically as the Dropdown Menu is closing.

Keyboard focus Action
True The Filter Criteria is cleared as the Dropdown Menu is closing.
False No attempt is made to change the current filter.

Dropdown Menu

Presents a list of suggestions that can be selected by the user. If no Filter Criteria is applied, then all items in the collection are displayed

Visibility

The Dropdown Menu can be expanded only when the control is in EditMode.

  Visibility
  Actions




  Expand

Left mouse click anywhere within the control area, with exception to the Remove Item Button of the item.

Down arrow key on the keyboard when the control has focus.

Change the Filter Criteria, by typing characters in the text area.

  Collapse

Left mouse click anywhere within the control area, with exception to the Remove Item Button of the item.

Return key.

The item that has focus in the list is selected

The Filter Criteria is removed

Esc key

Move focus away from the control by selecting any other control in the view or by deactivating the parent window.

Item Group

The items in the collection can be grouped by implementing IItemGroupAware. In addition to the header name, this interface exposes a property to manage the order in which the group headers are displayed.

Item Sorting

The sort order is based on the order of the items in the collection that was received when the ItemsSource is set.

Item Selection

Items can be added or removed from the selected items collection, by selecting them from the items present in the Dropdown Menu list.

Device Actions Description
Mouse Left mouse click The item that has selection focus in the list is selected/unselected.
Mouse Shift + Left mouse click All items between the previous and current item that has focus are selected.
Keyboard Return key - The item that has focus in the list is selected.
  • The Filter Criteria is removed.
  • The Dropdown Menu is closed | | Keyboard | Space key | The item that has focus in the list is selected/unselected. | | Keyboard | Shift + Up or Down key | The item that has focus in the list is selected/unselected. |

Disabled Item

Implement IItemEnabledAware to identify whether or not the items are enabled. When an item is not enabled, then it will not be selectable from the Dropdown Menu list and removed from the Selected Items Panel automatically.

Selected Item

Items in the Dropdown Menu list can be selected/unselected via the Mouse or Keyboard. When the item is selected, the style is updated to reflect a selected state.

Example Project

The example project demonstrates how to implement the Sdl.MultiSelectComboBox custom control to your project, and provides good examples in understanding the controls behaviours.

Examples

The following example creates an Sdl.MultiSelectComboBox. The example populates the control by binding the ItemsSource property to a collection of type object, that implements IItemEnabledAware and IItemGroupAware. The example also binds the SelectedItemsChangedBehaviour to a command to receive a notification of SelectedItemsChangedEventArgs whenever the selected items collection changes and then display those results in a TextBlock on the view. Additionally, both the selected and dropdown list item templates are customized to display an image along with the item name.

Example.xaml

csharp

    
        
            
                              
            
        
    
    
        
            
            
        
    

DataTemplate: MultiSelectComboBox.Dropdown.ListBox.ItemTemplate

csharp

    
        
            
            
            
        
 
        
        
        
            
                

            
        
    

DataTemplate: MultiSelectComboBox.SelectedItems.ItemTemplate

csharp

    
        
        
    

Style: MultiSelectComboBox.Image.Style

csharp

Style: MultiSelectComboBox.DefaultTextBlock.Style

csharp

The following example defines the data context (i.e. models:LanguageItems) that the Sdl.MultiSelectComboBox binds to from the previous example.

LanguageItems : INotifyPropertyChanged

…

LanguageItem : IItemEnabledAware, IItemGroupAware, INotifyPropertyChanged

…

SelectedItemsChangedCommand : ICommand

…

LanguageItemGroup : IItemGroup

csharp
public class LanguageItemGroup : IItemGroup
{
    public int Order { get; set; }
    public string Name { get; }
 
    public LanguageItemGroup(int index, string name)
    {
        Order = index;
        Name = name;
    }
 
    public override string ToString()
    {
        return Name;
    }
}

Remarks

The Sdl.MultiSelectComboBox allows the user to select an item from a Dropdown Menu list and optionally apply a filter on the list by typing text in the text box of the Selected Items Panel. The SelectionMode and IsEditable properties specify how the Item Selection behaves, especially when the user is interacting with items from the Selected Items Panel, as follows:

SelectionMode.Multiple (default) SelectionMode.Single
IsEditable is true (default) Multiple items can be selected/unselected from the Dropdown Menu list

The Remove Item Button is displayed in each of the selected items in the Selected Items Panel.

Items in the Selected Items Panel can be removed when the user hits the Delete or Back key | A single item can be selected from the Dropdown Menu list. When a new item is selected, it substitutes the previously selected item in the Selected Items Panel.

The Remove Item Button is displayed in each of the selected items in the Selected Items Panel.

Items in the Selected Items Panel can be removed when the user hits the Delete or Back key | | IsEditable is false | Multiple items can be selected/unselected from the Dropdown Menu list.

The Remove Item Button is not displayed in each of the selected items in the Selected Items Panel.

Items in the Selected Items Panel cannot be removed when the user hits the Delete or Back key | A single item can be selected from the Dropdown Menu list. When a new item is selected, it substitutes the previously selected item in the Selected Items Panel.

The Remove Item Button is not displayed in each of the selected items in the Selected Items Panel.

Items in the Selected Items Panel cannot be removed when the user hits the Delete or Back key |

Customizing the Style and template

You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a controls style and template, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate and Styling controls. The default style, template, and resources that define the look of the control are included in the generic.xaml file.

This table shows the resources used by the Sdl.MultiSelectComboBox control.

Resource key Description
MultiSelectComboBox.DropDown.Button.Background Drop down button background color at rest
MultiSelectComboBox.DropDown.Button.Border Drop down button border brush at rest
MultiSelectComboBox.DropDown.Button.Disabled.Background Drop down button background color when disabled
MultiSelectComboBox.DropDown.Button.Disabled.Border Drop down button border brush when disabled
MultiSelectComboBox.DropDown.Button.Disabled.Foreground Drop down button foreground color when disabled
MultiSelectComboBox.DropDown.Button.MouseOver.Background Drop down button background color when the mouse is hovering
MultiSelectComboBox.DropDown.Button.MouseOver.Border Drop down butt

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言