Murugan
Murugan

Reputation: 11

focussing cursor in textbox using xaml in wpf

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

Answers (2)

Mohammad Zare
Mohammad Zare

Reputation: 1509

use the FocusManager.FocusedElementlike 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

Bojo
Bojo

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

Related Questions