我有两个控件a ToolBar和a TextBox.ToolBar有一个Button打开Popup另一个的工具栏Button.
当前行为:如果我在里面单击TextBox并且它变得聚焦,然后单击按钮从中ToolBar打开弹出窗口TextBox仍然聚焦并接收所有键盘输入.
现在我知道这是FocusScope中的项目的默认行为ToolBar,但是当弹出窗口打开时我不需要这种行为.我怎么能避免呢?
这是一个例子:
<Window x:Class="WpfApplication67.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">
<Window.Resources>
</Window.Resources>
<StackPanel HorizontalAlignment="Left" Width="400">
<ToolBar>
<ToggleButton Name="openButton">Open Popup</ToggleButton>
<Popup Focusable="True"
Placement="Right"
StaysOpen="False"
IsOpen="{Binding IsChecked, ElementName=openButton, Mode=TwoWay}"
PlacementTarget="{Binding ElementName=openButton}">
<StackPanel
Width="100"
Height="100"
Background="DarkGray"
Focusable="True">
<Button>More</Button>
</StackPanel>
</Popup>
</ToolBar>
<TextBox Text="Set focus on this..." />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
编辑:我正在努力寻找一个解释,关于谁将焦点移动到嵌套的FocusScope内的按钮点击,以及如何阻止一些按钮(如Popup中的那个)进行操作.
wpf ×1