相关疑难解决方法(0)

WPF MVVM KeyBinding无法立即识别,并不总是有效

无论出于何种原因,只要我的WPF应用程序加载,我的UserControl的KeyBinding就不能正常工作.在我按下表单上的按钮后它们可以工作,但是当我通过单击或alt tabbing或移动或类似的东西将焦点设置到表单时它们不起作用.当他们工作时我的输入键打印一个随机数.(有时5,有时7等...).

<UserControl x:Class="WpfCalculator.View.CalculatorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300"
    >
<UserControl.InputBindings>
    <KeyBinding Key="DELETE" Command="{Binding Path=IBackspaceOnInput}" />
    <KeyBinding Key="BACKSPACE" Command="{Binding Path=IBackspaceOnInput}" />

    <KeyBinding Key="NUMPAD0" Command="{Binding Path=IAppendToUserInput}" CommandParameter="0" />
    <KeyBinding Key="NUMPAD1" Command="{Binding Path=IAppendToUserInput}" CommandParameter="1" />
    <KeyBinding Key="NUMPAD2" Command="{Binding Path=IAppendToUserInput}" CommandParameter="2" />
    <KeyBinding Key="NUMPAD3" Command="{Binding Path=IAppendToUserInput}" CommandParameter="3" />
    <KeyBinding Key="NUMPAD4" Command="{Binding Path=IAppendToUserInput}" CommandParameter="4" />
    <KeyBinding Key="NUMPAD5" Command="{Binding Path=IAppendToUserInput}" CommandParameter="5" />
    <KeyBinding Key="NUMPAD6" Command="{Binding Path=IAppendToUserInput}" CommandParameter="6" />
    <KeyBinding Key="NUMPAD7" Command="{Binding Path=IAppendToUserInput}" CommandParameter="7" />
    <KeyBinding Key="NUMPAD8" Command="{Binding Path=IAppendToUserInput}" CommandParameter="8" />
    <KeyBinding Key="NUMPAD9" Command="{Binding Path=IAppendToUserInput}" CommandParameter="9" /> …
Run Code Online (Sandbox Code Playgroud)

wpf key-bindings mvvm c#-4.0

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c#-4.0 ×1

key-bindings ×1

mvvm ×1

wpf ×1