【问题标题】:Can't use KeyUp and KeyBinding on the same control不能在同一个控件上使用 KeyUp 和 KeyBinding
【发布时间】:2015-11-09 13:48:18
【问题描述】:

我遇到了一些不寻常的行为,我想使用KeyBindingEnter 键绑定到我的视图模型中的命令,但我也想订阅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 事件?

【问题讨论】:

标签: wpf xaml events


【解决方案1】:

我不相信这是可能的,因为控件需要有两个不同的数据上下文,据我所知这是不可能的。

编辑:实际上在进一步阅读后,您可以执行以下操作: Multiple dataContext for one control - MVVM

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多