syncfusion-wpf-combobox

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implementing Syncfusion WPF ComboBox (ComboBoxAdv)

实现Syncfusion WPF ComboBox(ComboBoxAdv)控件

Comprehensive guide for implementing the Syncfusion® WPF ComboBoxAdv control, a powerful dropdown component that allows users to type a value or choose options from a list with support for multiselection, editing, autocomplete, data binding, and advanced features.
本指南详细介绍如何实现Syncfusion® WPF ComboBoxAdv控件,这是一个功能强大的下拉组件,支持用户输入值或从列表中选择选项,具备多选、编辑、自动完成、数据绑定等高级功能。

When to Use This Skill

适用场景

Use this skill when you need to:
  • Implement dropdown selection in WPF applications
  • Enable multiselection with checkboxes or tokens
  • Add editable dropdowns with autocomplete functionality
  • Bind data to dropdown controls using MVVM patterns
  • Customize item display with templates
  • Configure watermarks (default text) for user prompts
  • Set custom delimiters for multiselect displays
  • Integrate with Expression Blend for design-time editing
  • Apply themes using SfSkinManager or ThemeStudio
在以下场景中可使用本技能:
  • 在WPF应用中实现下拉选择功能
  • 启用带复选框或令牌的多选功能
  • 添加带自动完成功能的可编辑下拉框
  • 使用MVVM模式将数据绑定到下拉控件
  • 通过模板自定义项的显示样式
  • 配置水印(默认文本)以提示用户
  • 为多选显示设置自定义分隔符
  • 与Expression Blend集成以支持设计时编辑
  • 使用SfSkinManager或ThemeStudio应用主题

Component Overview

组件概述

The
ComboBoxAdv
control (
Syncfusion.Windows.Tools.Controls.ComboBoxAdv
) extends standard WPF dropdown functionality with:
Key Features:
  • Multiselection with checkboxes, tokens, OK/Cancel buttons
  • Editable mode with autocomplete (suggest mode)
  • Data binding via ItemsSource with DisplayMemberPath
  • Token display for selected items with close icons
  • Watermark support (DefaultText property)
  • Custom delimiters for multiselect display
  • Item templates for complex UI
  • Theme support with built-in and custom themes
  • Expression Blend integration for design-time editing
Namespace:
Syncfusion.Windows.Tools.Controls

Assembly:
Syncfusion.Shared.WPF

Schema:
http://schemas.syncfusion.com/wpf
ComboBoxAdv
控件(
Syncfusion.Windows.Tools.Controls.ComboBoxAdv
)扩展了标准WPF下拉框的功能,具备以下特性:
核心功能:
  • 多选支持:包含复选框、令牌、确定/取消按钮
  • 可编辑模式:搭配自动完成(建议模式)
  • 数据绑定:通过ItemsSource和DisplayMemberPath实现
  • 令牌显示:选中项以带关闭图标的令牌形式展示
  • 水印支持:通过DefaultText属性设置
  • 自定义分隔符:用于多选内容的显示分隔
  • 项模板:支持复杂UI的自定义
  • 主题支持:内置主题与自定义主题
  • Expression Blend集成:支持设计时编辑
命名空间:
Syncfusion.Windows.Tools.Controls

程序集:
Syncfusion.Shared.WPF

架构:
http://schemas.syncfusion.com/wpf

Documentation and Navigation Guide

文档与导航指南

Getting Started

快速入门

📄 Read: references/getting-started.md
  • Installation and assembly deployment
  • Adding control via designer, XAML, and C#
  • Creating data models and ViewModels
  • Basic data binding patterns
  • DisplayMemberPath configuration
  • ItemTemplate customization
  • Theme setup and application
📄 参考文档: references/getting-started.md
  • 安装与程序集部署
  • 通过设计器、XAML和C#添加控件
  • 创建数据模型与ViewModel
  • 基础数据绑定模式
  • DisplayMemberPath配置
  • ItemTemplate自定义
  • 主题设置与应用

Selection and MultiSelection

选择与多选功能

📄 Read: references/selection-multiselection.md
  • Single selection (SelectedItem, SelectedIndex, SelectedValue)
  • Enabling multiselection (AllowMultiSelect)
  • Programmatic selection with SelectedItems
  • SelectAll functionality
  • OK/Cancel buttons for multiselect
  • Overriding OnItemChecked/OnItemUnchecked
  • Token support (EnableToken) for visual item representation
  • Token editing and keyboard access
  • SelectionChanged event handling
📄 参考文档: references/selection-multiselection.md
  • 单选功能(SelectedItem、SelectedIndex、SelectedValue)
  • 启用多选(AllowMultiSelect)
  • 通过SelectedItems实现程序化选择
  • 全选功能
  • 多选确定/取消按钮
  • 重写OnItemChecked/OnItemUnchecked方法
  • 令牌支持(EnableToken)用于可视化项展示
  • 令牌编辑与键盘操作
  • SelectionChanged事件处理

Editing and AutoComplete

编辑与自动完成

📄 Read: references/editing-autocomplete.md
  • IsEditable property for text input
  • AutoComplete modes (Suggest, None)
  • Filtering dropdown items dynamically
  • Editable mode with token support
  • Text search and item matching
📄 参考文档: references/editing-autocomplete.md
  • IsEditable属性启用文本输入
  • 自动完成模式(Suggest、None)
  • 动态过滤下拉项
  • 带令牌支持的可编辑模式
  • 文本搜索与项匹配

Watermark and Delimiter

水印与分隔符

📄 Read: references/watermark-delimiter.md
  • DefaultText property for watermarks
  • SelectedValueDelimiter customization
  • Usage patterns and best practices
📄 参考文档: references/watermark-delimiter.md
  • DefaultText属性设置水印
  • SelectedValueDelimiter自定义
  • 使用模式与最佳实践

Data Binding

数据绑定

📄 Read: references/data-binding.md
  • ItemsSource binding fundamentals
  • Creating MVVM-compatible models and ViewModels
  • DisplayMemberPath vs ItemTemplate
  • ObservableCollection patterns
  • Two-way binding with SelectedItems
  • INotifyPropertyChanged implementation
📄 参考文档: references/data-binding.md
  • ItemsSource绑定基础
  • 创建兼容MVVM的模型与ViewModel
  • DisplayMemberPath与ItemTemplate对比
  • ObservableCollection模式
  • SelectedItems双向绑定
  • INotifyPropertyChanged实现

Customization and Blendability

自定义与Blend集成

📄 Read: references/customization-blendability.md
  • Expression Blend workflow
  • Style editing and template customization
  • Theme application with SfSkinManager
  • Creating custom themes with ThemeStudio
  • Control appearance customization
📄 参考文档: references/customization-blendability.md
  • Expression Blend工作流
  • 样式编辑与模板自定义
  • 使用SfSkinManager应用主题
  • 通过ThemeStudio创建自定义主题
  • 控件外观自定义

Quick Start

快速开始示例

Basic ComboBoxAdv with Static Items

静态项基础ComboBoxAdv

xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
    <Grid>
        <syncfusion:ComboBoxAdv Height="30" Width="200"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center">
            <syncfusion:ComboBoxItemAdv Content="Denmark" />
            <syncfusion:ComboBoxItemAdv Content="New Zealand" />
            <syncfusion:ComboBoxItemAdv Content="Canada" />
            <syncfusion:ComboBoxItemAdv Content="Russia" />
            <syncfusion:ComboBoxItemAdv Content="Japan" />
        </syncfusion:ComboBoxAdv>
    </Grid>
</Window>
xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
    <Grid>
        <syncfusion:ComboBoxAdv Height="30" Width="200"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center">
            <syncfusion:ComboBoxItemAdv Content="Denmark" />
            <syncfusion:ComboBoxItemAdv Content="New Zealand" />
            <syncfusion:ComboBoxItemAdv Content="Canada" />
            <syncfusion:ComboBoxItemAdv Content="Russia" />
            <syncfusion:ComboBoxItemAdv Content="Japan" />
        </syncfusion:ComboBoxAdv>
    </Grid>
</Window>

Data-Bound ComboBoxAdv with MVVM

基于MVVM的数据绑定ComboBoxAdv

csharp
// Model
public class Country
{
    public string Name { get; set; }
    public string Code { get; set; }
}

// ViewModel
public class ViewModel : INotifyPropertyChanged
{
    private ObservableCollection<Country> countries;
    public ObservableCollection<Country> Countries
    {
        get { return countries; }
        set { countries = value; OnPropertyChanged(nameof(Countries)); }
    }

    public ViewModel()
    {
        Countries = new ObservableCollection<Country>
        {
            new Country { Name = "Denmark", Code = "DK" },
            new Country { Name = "New Zealand", Code = "NZ" },
            new Country { Name = "Canada", Code = "CA" }
        };
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string name) =>
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
xml
<Window.DataContext>
    <local:ViewModel />
</Window.DataContext>
<syncfusion:ComboBoxAdv ItemsSource="{Binding Countries}"
                        DisplayMemberPath="Name"
                        Height="30" Width="200"/>
csharp
// 模型
public class Country
{
    public string Name { get; set; }
    public string Code { get; set; }
}

// ViewModel
public class ViewModel : INotifyPropertyChanged
{
    private ObservableCollection<Country> countries;
    public ObservableCollection<Country> Countries
    {
        get { return countries; }
        set { countries = value; OnPropertyChanged(nameof(Countries)); }
    }

    public ViewModel()
    {
        Countries = new ObservableCollection<Country>
        {
            new Country { Name = "Denmark", Code = "DK" },
            new Country { Name = "New Zealand", Code = "NZ" },
            new Country { Name = "Canada", Code = "CA" }
        };
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string name) =>
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
xml
<Window.DataContext>
    <local:ViewModel />
</Window.DataContext>
<syncfusion:ComboBoxAdv ItemsSource="{Binding Countries}"
                        DisplayMemberPath="Name"
                        Height="30" Width="200"/>

Common Patterns

常见实现模式

Pattern 1: Multiselection with Tokens

模式1:带令牌的多选功能

xml
<syncfusion:ComboBoxAdv AllowMultiSelect="True"
                        IsEditable="True"
                        EnableToken="True"
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="Auto" Width="300"/>
xml
<syncfusion:ComboBoxAdv AllowMultiSelect="True"
                        IsEditable="True"
                        EnableToken="True"
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="Auto" Width="300"/>

Pattern 2: Editable with AutoComplete

模式2:带自动完成的可编辑下拉框

xml
<syncfusion:ComboBoxAdv IsEditable="True"
                        AutoCompleteMode="Suggest"
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="30" Width="200"/>
xml
<syncfusion:ComboBoxAdv IsEditable="True"
                        AutoCompleteMode="Suggest"
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="30" Width="200"/>

Pattern 3: Watermark with Delimiter

模式3:带水印与分隔符的下拉框

xml
<syncfusion:ComboBoxAdv AllowMultiSelect="True"
                        DefaultText="Select items..."
                        SelectedValueDelimiter=" | "
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="30" Width="300"/>
xml
<syncfusion:ComboBoxAdv AllowMultiSelect="True"
                        DefaultText="Select items..."
                        SelectedValueDelimiter=" | "
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="30" Width="300"/>

Pattern 4: Multiselect with OK/Cancel

模式4:带确定/取消按钮的多选下拉框

xml
<syncfusion:ComboBoxAdv AllowMultiSelect="True"
                        AllowSelectAll="True"
                        EnableOKCancel="True"
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="30" Width="250"/>
xml
<syncfusion:ComboBoxAdv AllowMultiSelect="True"
                        AllowSelectAll="True"
                        EnableOKCancel="True"
                        ItemsSource="{Binding Items}"
                        DisplayMemberPath="Name"
                        Height="30" Width="250"/>

Key Properties

核心属性

PropertyTypeDescription
AllowMultiSelect
boolEnables multiple item selection
IsEditable
boolAllows text input and editing
EnableToken
boolDisplays selected items as tokens (multiselect)
AutoCompleteMode
AutoCompleModesSuggest or None for autocomplete
DefaultText
stringWatermark text when no item selected
SelectedValueDelimiter
stringSeparator between selected items
ItemsSource
IEnumerableData collection for binding
DisplayMemberPath
stringProperty path for item display
SelectedItem
objectCurrently selected item
SelectedItems
ObservableCollection<object>Collection of selected items (multiselect)
SelectedIndex
intIndex of selected item
EnableOKCancel
boolShows OK/Cancel buttons in dropdown
AllowSelectAll
boolAdds "Select All" option
属性类型描述
AllowMultiSelect
bool启用多项选择功能
IsEditable
bool允许文本输入与编辑
EnableToken
bool选中项以令牌形式展示(多选场景)
AutoCompleteMode
AutoCompleModes自动完成模式:Suggest或None
DefaultText
string未选中项时的水印文本
SelectedValueDelimiter
string选中项之间的分隔符
ItemsSource
IEnumerable用于绑定的数据源集合
DisplayMemberPath
string项展示的属性路径
SelectedItem
object当前选中的项
SelectedItems
ObservableCollection<object>选中项集合(多选场景)
SelectedIndex
int选中项的索引
EnableOKCancel
bool下拉框中显示确定/取消按钮
AllowSelectAll
bool添加"全选"选项

Common Use Cases

常见应用场景

  1. Country/Region Selector - Single selection with data binding
  2. Tag Selector - Multiselection with tokens for visual feedback
  3. Searchable Dropdown - Editable with autocomplete for large lists
  4. Category Filter - Multiselection with delimiters
  5. Form Input with Prompt - Watermark text for user guidance
  6. Bulk Selection - Select All with OK/Cancel for confirmation
  1. 国家/地区选择器 - 带数据绑定的单选功能
  2. 标签选择器 - 带令牌可视化反馈的多选功能
  3. 可搜索下拉框 - 针对大型列表的可编辑自动完成下拉框
  4. 分类筛选器 - 带分隔符的多选功能
  5. 带提示的表单输入 - 用于用户引导的水印文本
  6. 批量选择 - 带确定/取消确认的全选功能

See Also

相关链接