WPF ComboBox 输入框 汉字输入法 错误联动

问题

在使用ComboBox的输入框检索的时候,使用汉字输入法,ComboBox的Text属性没有正常更新。明明已经选中了item,但是文本框显示的不是item的text,而是用于检索的字。

解决方法

注册ComboBox的PreviewTextInput事件。

private void Cb_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
    if (Cb.Text == DC.SelectItem?.Name)
    {
        e.Handled = true;
    }
}
原文地址:https://www.cnblogs.com/naergaga/p/11381731.html