dcockerham
Topic Author
Posts: 11
Joined: 10 Apr 2021, 00:44

Can't move Focus from ListBox to out-of-view element?

11 Oct 2022, 20:34

I'm running into some behavior that seems odd to me, I'm trying to figure out if there's just something I don't understand about it or if it's some sort of bug.

I'm using multiple ListBoxes within a single ScrollViewer to make a a single extended vertically scrolling box with multiple 2-column lists in it. If I scroll all the way down to the bottom of the first list, and the second list is currently offscreen, then the Focus will NOT move to the second list even when I am pressing the down key. However, if I scroll downward (such as with the mouse wheel or right joystick) until the second list is partially visible, the Focus is able to move to the second list. (The same effect occurs when scrolling up.) As far as I can tell, other elements don't seem to have this problem, just the ListBox.

Is this behavior intentional? And if so, is there a simple way around it?

For additional context, we overrode the ListBox template so that it wouldn't have an internal ScrollViewer, so that they would play nicely with being gathered together in an external ScrollViewer. Our code looks something like this:
    <Grid
      Width="1144"
      Height="770"
      VerticalAlignment="Stretch">
      <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
        <StackPanel>
          <ListBox
              Height="auto"
              HorizontalContentAlignment="Stretch"
              VerticalContentAlignment="Stretch"
              ScrollViewer.VerticalScrollBarVisibility="Disabled"
              ItemTemplate="{DynamicResource MyItemTemplateStyle}"
              ItemsSource="{Binding FirstSource}">
            <ListBox.Template>
              <ControlTemplate>
                <ItemsPresenter />
              </ControlTemplate>
            </ListBox.Template>
            <ListBox.ItemsPanel>
              <ItemsPanelTemplate>
                <UniformGrid VerticalAlignment="Top" Columns="2" />
              </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
          </ListBox>
          <ListBox
              Height="auto"
              HorizontalContentAlignment="Stretch"
              VerticalContentAlignment="Stretch"
              ScrollViewer.VerticalScrollBarVisibility="Disabled"
              ItemTemplate="{DynamicResource MyItemTemplateStyle}"
              ItemsSource="{Binding SecondSource}">
            <ListBox.Template>
              <ControlTemplate>
                <ItemsPresenter />
              </ControlTemplate>
            </ListBox.Template>
            <ListBox.ItemsPanel>
              <ItemsPanelTemplate>
                <UniformGrid VerticalAlignment="Top" Columns="2" />
              </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
          </ListBox>
        </StackPanel>
      </ScrollViewer>
    </Grid>
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Can't move Focus from ListBox to out-of-view element?

17 Oct 2022, 14:30

Hi, sorry for the late reply.

This is caused by how our current implementation of the keyboard navigation deals with clipped elements (out of ScrollViewer visible viewport).
We have an open issue #2242 to fix it in relation with this other post: viewtopic.php?t=2521
We'll solve it for the next release.
 
dcockerham
Topic Author
Posts: 11
Joined: 10 Apr 2021, 00:44

Re: Can't move Focus from ListBox to out-of-view element?

17 Oct 2022, 18:18

Ah, I see. Thank you!

Who is online

Users browsing this forum: No registered users and 15 guests