c# - 可编辑的组合框将不允许写入
问题描述
我正在使用具有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>
手动选择时它工作正常,但书写不起作用(按键不输入任何文本)。唯一可行的方法是使用鼠标或向上/向下箭头选择一个项目,然后使用退格键删除其中的字符。我错过了什么?
解决方案
在父控件e.Handled
中设置为,因此只为子控件执行处理程序 ( ),这就是为什么我只能删除或粘贴文本但不能写入任何内容的原因。true
PreviewKeyDown
ComboBox
推荐阅读
- python - 如何使用 Python 将 Google 表单链接到 Google 表格?
- c++ - 编译错误 c++(需要替换),线程有问题吗?
- sql - 如何按属性分组但显示嵌套属性的值?
- flutter - Flutter 中的自定义小部件构造函数
- excel - EXCEL 根据展示位置汇总分数(结合 VLOOKUP 和 SUM)
- vb.net - 使用 Ghostscript.NET 包装器打印 PDF - 空白页
- c# - 为什么我的 Access DB 拒绝插入日期时间?
- multithreading - 无法理解 GDB 回溯输出
- ruby-on-rails - rails 5 - 根据页面呈现不同的链接
- java - 如何创建一个每次点击都会给你建议的意图