private void TextBox1_TextChanged(object sender, TextChangedEventArgs e)
{
txt1_focus.Focus();
}
wpfでxamlファイルを使用して上記のコードを実現するにはどうすればよいですか。
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>
http://cloudstore.blogspot.com/2008/06/setting-initial-focus-in-wpf.html
このサイトでは、特定のコントロールに初期フォーカスを設定する方法について説明しています。
<Window ...
FocusManager.FocusedElement="{Binding ElementName=TextBox1}">