多选组合框是一个具有多项选择功能的 WPF 自定义控件,还具有可自定义的功能,可对项目进行分组、排序和过滤。
多选组合框是一个具有多项选择功能的 WPF 自定义控件,还具有可自定义的功能,可对项目进行分组、排序和过滤。
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.
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 |
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. |
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. |
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
The Dropdown Menu can be expanded only when the control is in EditMode.
Visibility
Actions
ExpandLeft 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.
CollapseLeft 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.
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.
The sort order is based on the order of the items in the collection that was received when the ItemsSource is set.
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. |
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.
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.
The example project demonstrates how to implement the Sdl.MultiSelectComboBox custom control to your project, and provides good examples in understanding the controls behaviours.
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
DataTemplate: MultiSelectComboBox.Dropdown.ListBox.ItemTemplate
DataTemplate: MultiSelectComboBox.SelectedItems.ItemTemplate
Style: MultiSelectComboBox.Image.Style
Style: MultiSelectComboBox.DefaultTextBlock.Style
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
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;
}
}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 |
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,或尚未同步最近议题。