gpt4 book ai didi

wpf - 如何将焦点设置在文本框或密码框上

转载 作者:行者123 更新时间:2023-12-04 16:47:54 27 4
gpt4 key购买 nike

当我登录到我的应用程序时如何设置焦点,当登录窗口打开时我想在不使用鼠标的情况下在此输入密码

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com