Best practices for Focus and input handling
Posted: 29 Jan 2026, 11:03
Hey there,
I have been using Noesis for a game project for about 4 months now. By large I am finding it powerful. We have integrated it to our own C++ based engine.
I am struggling to understand how I'm expected to work with Focus handling. The game we are making is primarily aimed at Gamepad input, so this is an important topic for me as we will not be able to move focus with mouse on some platforms, meaning the Focus system must be robust and not drop focus or incorrectly placing focus when opening menus.
In our engine, we pre load XAMLs and create views, but they may not be visible until our visibility system tells them to start drawing.
I am working on a menu now that will at some point be given a list of options and be told to start showing. At this point I will want to set keyboard focus on the listbox of the menu.
However, I find I need to press down on the keyboard/gamepad once to give focus to the list before I can start navigating the list options.
I added an event listener for the Loaded event and fired a SetFocusAction within it, but I suppose the problem is that I may have misunderstood when the Loaded event is fired. I got the impression that it would fire when elements were added to the view (and that should happen after updating the viewmodel array of list options, right?), but I seem to be getting the Loaded event when first setting the view size, which happens only the first time it renders.
I'm attaching something similar to what I'm trying, but obviously I am using databinding for ItemsSource rather than hard coding the list options.
Do you have any suggestions for this?
I'm not sure if there's something wrong in our integration, or if I am thinking about focus the wrong way.
Cheers
I have been using Noesis for a game project for about 4 months now. By large I am finding it powerful. We have integrated it to our own C++ based engine.
I am struggling to understand how I'm expected to work with Focus handling. The game we are making is primarily aimed at Gamepad input, so this is an important topic for me as we will not be able to move focus with mouse on some platforms, meaning the Focus system must be robust and not drop focus or incorrectly placing focus when opening menus.
In our engine, we pre load XAMLs and create views, but they may not be visible until our visibility system tells them to start drawing.
I am working on a menu now that will at some point be given a list of options and be told to start showing. At this point I will want to set keyboard focus on the listbox of the menu.
However, I find I need to press down on the keyboard/gamepad once to give focus to the list before I can start navigating the list options.
I added an event listener for the Loaded event and fired a SetFocusAction within it, but I suppose the problem is that I may have misunderstood when the Loaded event is fired. I got the impression that it would fire when elements were added to the view (and that should happen after updating the viewmodel array of list options, right?), but I seem to be getting the Loaded event when first setting the view size, which happens only the first time it renders.
I'm attaching something similar to what I'm trying, but obviously I am using databinding for ItemsSource rather than hard coding the list options.
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors">
<ListBox
SelectedIndex="0"
Focusable="True"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
MaxWidth="600"
MaxHeight="800">
<ListBoxItem Content="Test 1" />
<ListBoxItem Content="Test 2" />
<ListBoxItem Content="Test 3" />
<i:Interaction.Triggers>
<b:EventTrigger EventName="Loaded">
<noesis:SetFocusAction />
</b:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
</Grid>
I'm not sure if there's something wrong in our integration, or if I am thinking about focus the wrong way.
Cheers