c# - 使用键盘作为XAML和C#计算器的输入

标签 c# wpf xaml mvvm

我正在使用Visual Studio(C#和XAML)创建一个计算器。我希望能够键入数字和运算来进行计算。无需单击结果屏幕(就像Windows默认计算器一样)。我该如何实现?我正在使用MVVM概念创建计算器,就像练习MVVM一样。

最佳答案

您将需要在XAML中使用KeyBinding并将命令绑​​定到 key 。

<Window.InputBindings>
   <KeyBinding Key="D1"
               Command="AddOneToEntryCommand" />
   <KeyBinding Key="Add"
               Command="AddCommand" />
   <KeyBinding Key="Subtract"
               Command="SubtractCommand" />
   <!-- Add bindings for all the keys and handle the logic in your commands -->
</Window.InputBindings>

关于c# - 使用键盘作为XAML和C#计算器的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32416834/

相关文章:

wpf - 拉伸(stretch) wpf 选项卡控件内容

c# - 如果知道类型,为什么要使用 "List<T> where T : SomeType"

c# - 获取文件的相对路径?

DataGridTemplateColumn 中的 WPF 数据绑定(bind) ComboBox

wpf - 取消 WPF 中验证错误时的 TextBox 输入

Wpf面板背景问题

c# - 如何处理此类问题 UnauthorizedAccessException Was handli Error?

c# - 从多个文本框中选择查询c#

c# - 从 WPF 中的不同线程更新 UI 控件时出现 "The calling thread cannot access this object because a different thread owns it"错误

c# - Windows IoT 上的 Windows Universal App 中的屏幕键盘?