<Grid x:Name="LayoutRoot">
<TextBox x:Name="TxtFocusOut" Height="74" Margin="186,149,225,0" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="26.667" TextChanged="TextBox_TextChanged"/>
</Grid>
private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
if(TxtFocusOut.Text.Length>=4)
{
MessageBox.Show("Four you typed four values");
}
}
单击消息框上的“确定”按钮后,光标应该从 texbox 中移出。但现在它在文本框中闪烁。我应该怎么做才能从 testbox 移出焦点?
最佳答案
FocusManager.SetFocusedElement(AnotherElementID);
通过这样做,this 将失去它的焦点,而焦点可以用于另一个元素。
或者
Keyboard.ClearFocus();
http://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.clearfocus.aspx
试试这些
关于c# - 如何从 wpf 中的文本框聚焦光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13750170/