首页 > 解决方案 > 可编辑的组合框将不允许写入

问题描述

我正在使用具有IsEditable=true使用以下代码创建的属性的组合框:

ComboBox buffer = new ComboBox()
{
        BorderBrush = null,
        Foreground = new SolidColorBrush(Colors.Black),
        Background = null,
        FontFamily = new FontFamily("Segoe UI Semilight"),
        FontSize = 24,
        IsEditable = true,
        IsTextSearchEnabled = true,
        IsTextSearchCaseSensitive = false,
        StaysOpenOnEdit = true,
};

它被添加到 ScrollViewer 中的 WrapPanel 中,定义如下:

<ScrollViewer Margin="582,107,142,240" 
              HorizontalAlignment="Left" 
              VerticalAlignment="Top" 
              Height="226" Width="357">
        <Border Background="White" 
                CornerRadius="10" 
                BorderBrush="Black" 
                BorderThickness="1" 
                MouseDown="Border_MouseDown" 
                MouseLeave="Border_MouseLeave" 
                MouseUp="Border_MouseUp">
            <WrapPanel x:Name="sourcesWrapPanel" Width="357"/>
        </Border>
</ScrollViewer>

手动选择时它工作正常,但书写不起作用(按键不输入任何文本)。唯一可行的方法是使用鼠标或向上/向下箭头选择一个项目,然后使用退格键删除其中的字符。我错过了什么?

标签: c#wpf

解决方案


在父控件e.Handled中设置为,因此只为子控件执行处理程序 ( ),这就是为什么我只能删除或粘贴文本但不能写入任何内容的原因。truePreviewKeyDownComboBox


推荐阅读