Wpf ScrollViewer窃取焦点
为什么在下一个XAML中单击禁用的按钮会导致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
<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>