【发布时间】:2020-07-05 04:51:18
【问题描述】:
目标:在 WPF 页面中,我希望用户能够按下预定的键序列,这些键将触发导致控件(按钮)出现的事件。我已经查看了所有可以找到的 KeyDown 和 Keyboard.KeyDown 事件,它们似乎没有在后面的代码中触发事件。
XAML:
<Page x:Class="KioskClient.Begin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:local="clr-namespace:KioskClient"
xmlns:uc="clr-namespace:KioskClient"
xmlns:controls="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Background="Black"
Title="SIMS Check In"
Keyboard.KeyDown="Page_KeyDown"
>
<DockPanel LastChildFill="True" Background="Black">
<!--Since you always want the Back, Next, Cancel button to be docked to
the bottom of the screen, put them first in the Dockpanel and dock them,
the other objects then fill the space.-->
<controls:UniformGrid Margin="100" Rows="1"
HorizontalAlignment="Center"
VerticalAlignment="Bottom" Background="Black" DockPanel.Dock="Bottom">
</DockPanel>
</Page>
C#:
private void Page_KeyDown(object sender, KeyEventArgs e)
一旦我可以触发事件但事件没有触发,我就知道该怎么做。除了我设置“this.Focusable = true;”的页面本身,我不想专注于任何事情。在构造函数中。显然,我错过了一些东西。谁能告诉我这是什么?
【问题讨论】: