RisingSunStudios
Topic Author
Posts: 21
Joined: 12 Apr 2020, 09:56

Bug with ListBox keyboard navigation

20 Mar 2025, 09:52

Hey!

I've noticed in my own samples as well as the official samples that it appears as if the ListBox is focused by default, and requires 2 presses of the Down arrow before the focus is moved to the first ListBoxItem. I've tried forcing focus to the first ListBoxItem but then I get a strange behaviour with an outline around the ListBoxItem as if it has focused the container despite it not being Focusable. I have copied the QuestLog sample.

You can see this in the QuestLog sample here https://www.noesisengine.com/xamltoy/61 ... 2b96e30f94

If you load the sample and make sure you don't mouse-over any list items, it requires 2 down-button presses to move the selection.

Anyone have any idea why? It is quite an annoying bug!

Many thanks!
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Bug with ListBox keyboard navigation

24 Mar 2025, 18:56

Hi, when the sample is loaded the focus is in the page, the first key down moves the focus to the first item in the list (you can see it by adding a FocusVisualStyle to the ListBoxItem style), and the second key down moves the selection to the second item.

But you can place the focus at the ListBox when the page gets loaded if that is what you need. Just add a SetFocusAction to an EventTrigger for the Loaded event:
<ListBox x:Name="Quests" Style="{StaticResource QuestListStyle}"
  ItemContainerStyle="{StaticResource QuestListItemStyle}"
  ItemsSource="{Binding Children, Source={StaticResource Quests}}"
  SelectedIndex="0"
  DisplayMemberPath="Tag">
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
      <noesis:SetFocusAction/>
    </i:EventTrigger>
    <i:EventTrigger EventName="SelectionChanged">
      <ei:ControlStoryboardAction Storyboard="{StaticResource QuestSelected}"/>
    </i:EventTrigger>
  </i:Interaction.Triggers>
</ListBox>
Is this what you're looking for?
 
RisingSunStudios
Topic Author
Posts: 21
Joined: 12 Apr 2020, 09:56

Re: Bug with ListBox keyboard navigation

26 Mar 2025, 11:33

Hey thanks, I can't test this right now but I'll try it in the next week when back at my desk. I tried setting focus but got strange behaviour where the focus style and liet selection was out of sync. Maybe my mistake was trying to set focus to the listboxitem instead of the listbox on loaded.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Bug with ListBox keyboard navigation

26 Mar 2025, 12:58

Setting the focus in the ListBoxItem style would be more tricky, as it will try to do it for all the items in the list unless you add some kind of ConditionBehavior in addition to the use of AlternationIndex to only do it for the first item, and it doesn't seem necessary in this scenario as you can just focus the ListBox.

Anyway, our QuestLog sample in XamlToy is an old version (compared to the ones provided in our SDKs) and it was not right, we fixed it to set the focus in the list as expected.
 
RisingSunStudios
Topic Author
Posts: 21
Joined: 12 Apr 2020, 09:56

Re: Bug with ListBox keyboard navigation

26 Mar 2025, 13:08

Perfect, thank you! I'll check it out as soon as I'm home. Really appreciating Noesis so far in our current project!
 
RisingSunStudios
Topic Author
Posts: 21
Joined: 12 Apr 2020, 09:56

Re: Bug with ListBox keyboard navigation

28 Mar 2025, 17:20

Just confirming that setting focus to the listbox worked! Could have sworn I tried that but oh well - thanks very much for the assistance =)
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: Bug with ListBox keyboard navigation

28 Mar 2025, 18:22

Thank you for the feedback!

Who is online

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