KeyTrigger does not work
Hi, I am trying to use a command when a key is pressed. But the KeyTrigger does not work. I saw some samples and other posts but nothing. I am very new to Noesis so I don't know why it doesn't work.
Here is the xaml code
Those are the components that I included. Prehaps I forgot include another.
Here is the xaml code
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
xmlns:local="clr-namespace:GameGUI"
x:Class="GameGUI.Loading"
x:Name="LoadingControl" Focusable="True" IsTabStop="False">
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding State}" Comparison="NotEqual" Value="{x:Static local:State.Loading}">
<ei:ChangePropertyAction PropertyName="Visibility" Value="Hidden" />
</ei:DataTrigger>
<ei:DataTrigger Binding="{Binding State}" Comparison="Equal" Value="{x:Static local:State.Loading}">
<ei:ChangePropertyAction PropertyName="Visibility" Value="Visible" />
</ei:DataTrigger>
<ei:KeyTrigger Key="Esc" ActiveOnFocus="False">
<i:InvokeCommandAction Command="{Binding Game}"/>
</ei:KeyTrigger>
</i:Interaction.Triggers>
<Grid x:Name="LayoutRoot">
<Viewbox>
<StackPanel Margin="30">
<TextBlock Foreground="White" Text="Loading..."/>
<TextBlock Foreground="White" Text="Press Esc key to start"/>
</StackPanel>
</Viewbox>
</Grid>
</UserControl>
Code: Select all
Noesis::TypeOf<NoesisApp::Interaction>();
Noesis::RegisterComponent<NoesisApp::DataTrigger>();
Noesis::RegisterComponent<NoesisApp::TriggerCollection>();
Noesis::RegisterComponent<NoesisApp::KeyTrigger>();
Noesis::RegisterComponent<NoesisApp::InvokeCommandAction>();
Noesis::RegisterComponent<NoesisApp::ChangePropertyAction>();
Noesis::RegisterComponent<NoesisApp::EventTrigger>();
Noesis::RegisterComponent<NoesisApp::PropertyChangedTrigger>();
Noesis::RegisterComponent<NoesisApp::TriggerActionCollection>();
Noesis::RegisterComponent<NoesisApp::SetFocusAction>();
Noesis::RegisterComponent<Noesis::EnumConverter<NoesisApp::ComparisonConditionType>>();
Noesis::RegisterComponent<Noesis::EnumConverter<NoesisApp::KeyTriggerFiredOn>>();
-
sfernandez
Site Admin
- Posts: 2974
- Joined:
Re: KeyTrigger does not work
For a KeyTrigger to work (and the same happens for KeyBindings) the KeyDown routed event should be raised by some element inside the control defining the trigger or the control itself. This means that the keyboard focus should be set to any element inside the control or the control itself.
The order of routed events processing is as follows:
The order of routed events processing is as follows:
- PreviewKeyDown (tunnel) on root element.
- PreviewKeyDown (tunnel) on intermediate element #1.
- PreviewKeyDown (tunnel) on source focused element #2.
- KeyDown (bubble) on source focused element #2.
- KeyDown (bubble) on intermediate element #1.
- KeyDown (bubble) on root element.
-
sfernandez
Site Admin
- Posts: 2974
- Joined:
Re: KeyTrigger does not work
I see you have marked the post as solved, did you finally make it work?
Re: KeyTrigger does not work
Yes, it finally worked. Thanks for the help!
-
sfernandez
Site Admin
- Posts: 2974
- Joined:
Re: KeyTrigger does not work
Great, thanks for the update.
Who is online
Users browsing this forum: No registered users and 1 guest