且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单击wpf中的按钮时如何避免TextBox失去焦点?

更新时间:2022-05-23 22:40:55

当按钮代码>焦点变化

示例:

<StackPanel>
    <TextBox Name="txtbx" />
    <Button Content="Click Me!" FocusManager.FocusedElement="{Binding ElementName=txtbx}"/>
</StackPanel>

使用此解决方案,即使按下 ButtonTextBox LostFocus 也将始终聚焦 TextBox> 事件不会被触发

With this solution the The TextBox will always be focused even when the Button is pressed and the TextBox LostFocus event will not be fired