其实很简单,只要将容器控件中的附加属性FocusManager.IsFocusScope设为True就可以了
下面是个简单的用例:
<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"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation="Horizontal" FocusManager.IsFocusScope="True"> <ComboBox Width="100"> <ComboBoxItem>1</ComboBoxItem> <ComboBoxItem>2</ComboBoxItem> <ComboBoxItem>3</ComboBoxItem> </ComboBox> <ComboBox Width="100"> <ComboBoxItem>a</ComboBoxItem> <ComboBoxItem>b</ComboBoxItem> <ComboBoxItem>c</ComboBoxItem> </ComboBox> </StackPanel> <RichTextBox Grid.Row="1"/> </Grid> </Window>
以下是运行效果图