Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf ScrollViewer窃取焦点_Wpf_Focus_Scrollviewer - Fatal编程技术网

Wpf ScrollViewer窃取焦点

Wpf ScrollViewer窃取焦点,wpf,focus,scrollviewer,Wpf,Focus,Scrollviewer,为什么在下一个XAML中单击禁用的按钮会导致ScrollViewer从文本框中窃取焦点?是这样吗?解决办法是什么 <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" Heigh

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

<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”会有所帮助。但这是正确的解决方法吗?

是的,您可以这样做
IsFocusable=“False”
ishitestable=“False”

,但这是否会减少关注ScrollViewer滚动条按钮的可能性?这是一种解决方法还是一种正确的方法来去除ScrollViewer的聚焦性?我只是想确认一下,这确实有效,而且据我所知,它不会削弱选择ScrollViewer滚动条的能力。它只是去除了进入ScrollViewer的子控件的冒泡效果。使用它可能会有潜在的问题,但我还没有发现它们。
<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>