private void TextBox1_TextChanged(object sender, TextChangedEventArgs e)
{
txt1_focus.Focus();
}
如何在wpf中使用xaml文件来实现上述代码。
答案 0 :(得分:2)
使用下面的FocusManager.FocusedElement
:
<Window x:Class="UI.Views.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FocusManager.FocusedElement="{Binding ElementName=txtSearch}">
</Window>
答案 1 :(得分:1)
http://cloudstore.blogspot.com/2008/06/setting-initial-focus-in-wpf.html
该网站介绍了如何将初始焦点设置在某个控件上。
<Window ...
FocusManager.FocusedElement="{Binding ElementName=TextBox1}">