当WPF窗口显示后 如果想设置某个输入框为默认焦点 使用 FocusManager
-
<Grid FocusManager.FocusedElement="{Binding ElementName=inputbox}">
-
<TextBox Name="inputbox" HorizontalAlignment="Left" Height="24" Margin="10,10,0,0"
-
Text="{Binding SearchText, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
-
TextWrapping="Wrap" VerticalAlignment="Top" Width="161">
-
<TextBox.InputBindings>
-
<!--键盘事件绑定-->
-
<KeyBinding Command="{Binding Search_Click}" Key="Enter"/>
-
</TextBox.InputBindings>
-
</TextBox>
-
</Grid>