WPF窗口默认TextBox焦点

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Vblegend_2013/article/details/81771872

 当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>

猜你喜欢

转载自blog.csdn.net/Vblegend_2013/article/details/81771872