Wpf ScrollViewer焦点不会更改为外部控件

Wpf ScrollViewer焦点不会更改为外部控件,wpf,xaml,listbox,Wpf,Xaml,Listbox,我在TreeView中使用了ListBox <TreeView Height="300"> <TreeViewItem Header="Item1"/> <TreeViewItem Header="Item2"> <ListBox Height="100"> <ListBoxItem Content="Ite

我在TreeView中使用了ListBox

        <TreeView Height="300">
            <TreeViewItem Header="Item1"/>
            <TreeViewItem Header="Item2">
                <ListBox Height="100">
                    <ListBoxItem Content="Item1"/>
                    <ListBoxItem Content="Item2"/>
                    <ListBoxItem Content="Item3"/>
                    <ListBoxItem Content="Item4"/>
                    <ListBoxItem Content="Item5"/>
                    <ListBoxItem Content="Item6"/>
                    <ListBoxItem Content="Item7"/>
                    <ListBoxItem Content="Item8"/>
                </ListBox>
            </TreeViewItem>
            <TreeViewItem Header="Item3">
                <ListBox Height="100">
                    <ListBoxItem Content="Item1"/>
                    <ListBoxItem Content="Item2"/>
                    <ListBoxItem Content="Item3"/>
                    <ListBoxItem Content="Item4"/>
                    <ListBoxItem Content="Item5"/>
                    <ListBoxItem Content="Item6"/>
                    <ListBoxItem Content="Item7"/>
                    <ListBoxItem Content="Item8"/>
                </ListBox>
            </TreeViewItem>
            <TreeViewItem Header="Item4">
                <ListBox />
            </TreeViewItem>
            <TreeViewItem Header="Item5">
                <ListBox />
            </TreeViewItem>
            <TreeViewItem Header="Item6"/>
        </TreeView>
当我将鼠标指向ListBox并开始滚动时,ListBox将被滚动。当滚动结束时,我需要将焦点更改为TreeView滚动查看器,以便TreeView获得滚动。在这段代码中,当鼠标在ListBox内时,滚动不适用于TreeView。

在ListBox被滚动后,我需要将焦点更改为外部控件滚动查看器

这并不能很好地描述您的问题,但是如果您说您希望能够将焦点从列表框内部移动到列表框外部,那么您所需要的似乎就是学习如何使用箭头键从键盘导航列表框

如果焦点位于包含ListBox的TreeView项目上,则可以按向右箭头键展开该项目并遍历ListBoxItems。然后可以按向上和向下箭头键选择列表框中的上一项或下一项

查看完ListBoxItems后,可以按向左箭头键从ListBox导航回TreeView项目。然后,您可以按向上和向下箭头键再次浏览TreeViewItems

如果这对您的问题没有帮助,请编辑您的问题并添加问题的清晰描述

更新>>>

您可以通过处理以下命令来检测列表框何时已滚动到底部:

然后,您可以使用和聚焦下一个UI元素:


谢谢谢里登,我已经编辑了我的查询。我不想使用键盘,我需要滚动导航,也许你应该更仔细地问你的问题。
<ListBox ItemsSource="{Binding Days}" ScrollViewer.CanContentScroll="False" 
    ScrollViewer.ScrollChanged="ListBox_ScrollChanged" />
private void ListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
    ScrollViewer scrollViewer = (ScrollViewer)e.OriginalSource;
    if (scrollViewer.VerticalOffset + scrollViewer.ViewportHeight == 
        scrollViewer.ExtentHeight)
    {
        // The ListBox was scrolled to the bottom
    }
}
TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
UIElement focusedElement = Keyboard.FocusedElement as UIElement;
if (focusedElement != null) focusedElement.MoveFocus(request);