alexk
Topic Author
Posts: 2
Joined: 26 Aug 2023, 21:01

XYFocus<Direction> problem

03 Oct 2024, 20:23

Hello all.

I'm using Noesis engine to create a UI in a Unity project.
I have a XAML layout with multiple hidden or invisible grids with tons of elements, UserControls with complex templates and so on.
I'm using a gamepad to navigate the UI. The default element to element focus movement is not looking good so I'm using noesis:Element.XYFocus<Direction>="{Binding ElementName=ElementToGoTo}" .
In many cases this works as expected but not always. Sometimes focus just seems to disappear and I need multiple clicks to get it back into the active panel. It seems to never happen to buttons but very often to usercontrols with complex templates, as well as ItemsControls (like ListBoxes and ComboBoxes).
The destination ElementName is unique over the whole application.
What might be the reason for the focus to not go where I'm expecting it to go?
Also, is there a way to log a currently focused element in an Update function of some script?

Thank you!
 
User avatar
sfernandez
Site Admin
Posts: 3134
Joined: 22 Dec 2011, 19:20

Re: XYFocus<Direction> problem

04 Oct 2024, 10:50

Also, is there a way to log a currently focused element in an Update function of some script?
One technique for this is to use the FocusManager.FocusedElement. In your root xaml you can have something like this:
<UserControl ...
  x:Name="RootDocument"
  FocusManager.IsFocusScope="True">
  ...
  <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="20" IsHitTestVisible="False">
    <TextBlock Text="{Binding Path=(FocusManager.FocusedElement), ElementName=DocumentRoot}" FontSize="30" Foreground="#80FFFFFF"/>
    <TextBlock Text="{Binding Path=(FocusManager.FocusedElement).Name, ElementName=DocumentRoot, StringFormat=' ({0})'}" FontSize="30" Foreground="#80FFFFFF"/>
  </StackPanel>
</UserControl>
The destination ElementName is unique over the whole application.
What might be the reason for the focus to not go where I'm expecting it to go?
Regarding this, the first thing to remark is that XYFocus properties can only be set on Controls, and also that the focus must be inside the control defining those properties in order to be used.

Anyway, if the behavior is erratic and not expected, there could be some bug in Noesis. If you can create a ticket in our bugtracker and provide some minimal xaml that reproduces your problem we can debug it and see what's wrong.

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests