ScrollViewer窃取焦点

Vic*_*yov 6 wpf focus scrollviewer

为什么在下一个XAML中单击禁用按钮会导致ScrollViewer从TextBox中窃取焦点?这样对吗?解决方法是什么?

<Window
x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
FocusManager.FocusedElement="{Binding ElementName=TextBox}">
<ScrollViewer>
    <StackPanel>
        <TextBox x:Name="TextBox"/>
        <Button IsEnabled="False" Content="Disabled Button"/>
    </StackPanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

在ScrollViewer上设置IsFocusable ="False"有帮助.但这是正确的解决方法吗?

Zah*_*tar 3

是的,你可以做IsFocusable="False"或者IsHitTestable="False"