ScrollViewer窃取焦点

时间:2011-09-16 05:54:20

标签: 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>

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

1 个答案:

答案 0 :(得分:2)

是的,您可以IsFocusable="False"IsHitTestable="False"