0
votes

Goal: From a WPF Page, I want a user to be able to press a pre-determined sequence of keys that will fire an event causing a control(button) to appear. I have looked at everything I can find for KeyDown and Keyboard.KeyDown events and they don't seem to fire the event in the code behind.

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)

I know what to do once I can get the event to fire but the event is not firing. I do not want to have to focus on anything but the Page itself which I set 'this.Focusable = true;' in the constructor. Obviously, I am missing something. Can anyone tell me what it is?

1

1 Answers

0
votes

Use Keyboard.KeyDown instead. That should solve your problem.

<Window ...
    Keyboard.KeyDown="Page_KeyDown">
    ...
</Window>