当我登录到我的应用程序时如何设置焦点,当登录窗口打开时我想在不使用鼠标的情况下在此输入密码
<PasswordBox x:Name="passwordbox" Grid.Row="1" Grid.Column="1" Margin="5,35,5,5" Width="280" Height="27" app:PasswordBoxAssistant.BindPassword="true" app:PasswordBoxAssistant.BoundPassword="{Binding TechUserModel.UserId,Mode=TwoWay,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" VerticalAlignment="Center">
最佳答案
我已经针对这种情况尝试了各种解决方案,我发现最有效的是使用 FocusManager.FocusedElement:
<Window x:Class="StackOverflow.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test" Height="300" Width="300"
FocusManager.FocusedElement="{Binding ElementName=Box}">
<Grid>
<TextBox x:Name="Box"/>
</Grid>
</Window>
关于wpf - 如何将焦点设置在文本框或密码框上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36401408/