【发布时间】:2015-11-09 13:48:18
【问题描述】:
我遇到了一些不寻常的行为,我想使用KeyBinding 将Enter 键绑定到我的视图模型中的命令,但我也想订阅KeyUp 事件视图代码隐藏中的控件。这是一个例子:
<TextBox Name="txtCustomBarcode"
KeyUp="CustomBarcode_KeyUp">
<TextBox.InputBindings>
<KeyBinding Command="{Binding ScanBarcodeCommand}"
CommandParameter="{Binding Text, ElementName=txtCustomBarcode}"
Key="Enter"/>
</TextBox.InputBindings>
</TextBox>
如果我使用这种方法,那么只有命令会被执行,代码隐藏事件会被忽略。如果我删除KeyBinding,则KeyUp 事件会按预期调用。
有没有办法可以在同一个控件上使用KeyBinding 和 KeyUp 事件?
【问题讨论】: