Reputation: 11
private void TextBox1_TextChanged(object sender, TextChangedEventArgs e)
{
txt1_focus.Focus();
}
How can i achieve the above code using using xaml file in wpf.
Upvotes: 1
Views: 1147
Reputation: 1509
use the FocusManager.FocusedElement
like below:
<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>
Upvotes: 2
Reputation: 313
http://cloudstore.blogspot.com/2008/06/setting-initial-focus-in-wpf.html
This site explains how to set the initial focus on a certain control.
<Window ...
FocusManager.FocusedElement="{Binding ElementName=TextBox1}">
Upvotes: 1