wpf下ComboBox自动过滤下拉内容,在xaml中使用下面这个类就可以了

这个博客介绍了一个自定义的WPF控件`AutoFilteredComboBox`,它能根据输入的文本自动过滤下拉列表的内容。该控件注册了文本改变事件,并提供了`IsCaseSensitive`属性来设置是否区分大小写。当焦点落在ComboBox上时,可以通过`DropDownOnFocus`属性控制是否自动展开下拉列表。博客还展示了如何处理选择和过滤逻辑。
摘要由CSDN通过智能技术生成
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows;
using System.Globalization;

namespace YouNameSpace
{
    class AutoFilteredComboBox : ComboBox
    {

        private int silenceEvents = 0;

        /// <summary>
        /// Creates a new instance of <see cref="AutoFilteredComboBox" />.
        /// </summary>
        public AutoFilteredComboBox()
        {
            DependencyPropertyDescriptor textProperty = DependencyPropertyDescriptor.FromProperty(
                ComboBox.TextProperty, typeof(AutoFilteredComboBox));
            textProperty.AddValueChanged(this, this.OnTextChanged);

            this.RegisterIsCaseSensitiveChangeNotification();
            this.IsEditable = true;
        }

        #region IsCaseSensitive Dependency Property
        /// <summary>
        /// The <see cref="DependencyProperty"/> object of the <see cref="IsCaseSensitive" /> dependency property.
        /// </summary>
        public static readonly DependencyProperty IsCaseSensitiveProperty =
            DependencyProperty.Register("IsCaseSensitive", typeof(bool), typeof(AutoFilteredComboBox), new UIPropertyMetadata(false));

        /// <summary>
        /// Gets or sets the way the combo box treats the case sensitivity of typed text.
        /// </summary>
        /// <value>The way the combo box treats the case sensitivity of typed text.</value>
        [System.ComponentModel.Description("The way the combo box treats the case sensitivity of typed text.")]
        [System.ComponentModel.Category("AutoFiltered ComboBox")]
        [System.ComponentModel.DefaultValue(true)]
        public bool IsCa

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值