GamepadTrigger to Open Button Context Menu with Gamepad
Posted: 15 Oct 2024, 19:56
I have a button with a context menu that can be accessed via right clicking and I am trying to have it work with gamepad input as well. Adding an event trigger for the mouse click event does seem to work (as in the example below) but adding a GamepadTrigger seems to be ineffective. It also doesn't seem to matter what button I use for the GamepadTrigger.
Is there an intended way to bind a gamepad button to an event like opening the context menu? Ideally, the approach is in xaml since this button is part of a ControlTemplate and has no code behind.
I tried to search the forum for similar issues and I wasn't able to find anything. My apologies if this was already addressed somewhere and I missed it!
Is there an intended way to bind a gamepad button to an event like opening the context menu? Ideally, the approach is in xaml since this button is part of a ControlTemplate and has no code behind.
Code: Select all
<ControlTemplate x:Key="MyControlTemplate">
<Grid x:Name="Root">
<b:Interaction.Triggers>
<!-- Various DataTriggers to change visibility of context menu items -->
</b:Interaction.Triggers>
<Button x:Name="MyButton" Style="{StaticResource Button.Style}" IsEnabled="True">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:ChangePropertyAction TargetObject="{Binding ContextMenu, ElementName=MyButton}" PropertyName="PlacementTarget" Value="{Binding ElementName=MyButton, Mode=OneWay}"/>
<b:ChangePropertyAction TargetObject="{Binding ContextMenu, ElementName=MyButton}" PropertyName="IsOpen" Value="True"/>
</b:EventTrigger>
<noesis:GamepadTrigger Button="Accept" ActiveOnFocus="True">
<b:ChangePropertyAction TargetObject="{Binding ContextMenu, ElementName=MyButton}" PropertyName="PlacementTarget" Value="{Binding ElementName=MyButton, Mode=OneWay}"/>
<b:ChangePropertyAction TargetObject="{Binding ContextMenu, ElementName=MyButton}" PropertyName="IsOpen" Value="True"/>
</noesis:GamepadTrigger>
</b:Interaction.Triggers>
<Button.ContextMenu>
<ContextMenu>
<!-- some menu items -->
</ContextMenu>
</Button.ContextMenu>
</Button>
</Grid>
</ControlTemplate>