-2

I am fresh to wpf,start learning xaml last 3days,when i am creating the enter event for my textbox in xaml code i cont create y? how can i create enter evnet? some events no proble like click,textchanged events.

krishna
  • 11
  • 1
  • 4

3 Answers3

0

You want it only if the user press Enter when the focus is in the TextBox?

What you can do if your design is MVVM with commands:

At the same level as Window.Resources:

<Window.InputBindings>
    <KeyBinding Key="Enter" Command="{Binding EnterCommand}"/>
</Window.InputBindings>

But this will catch the Enter key anywhere in your window, not just if your focusing your TextBox...

mlemay
  • 1,622
  • 2
  • 32
  • 53
  • Thanks for ur reply,i want to create enter event for text box as like normal windows text box.the purpose is whenever i enter into text box select the text. like normal win app textbox.selectall() – krishna Mar 20 '13 at 12:20
0

You can use TextChanged event and the code for the handler,

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
KyloRen
  • 2,691
  • 5
  • 29
  • 59
0

There is no "Enter" event in WPF textbox. You should think of other events like : GotFocus, MouseEnter, MouseDown, GotKeybordFocus Depending what you need.

In xaml you write sth like :<TextBox Height="23" Canvas.Left="374" TextWrapping="Wrap" Text="TextBox" Canvas.Top="272" Width="120" GotFocus="TextBox_GotFocus_1"/>

but it's easier to use designer. Properties->Events -> doubleClick on the event you need to generate for control.

MicRot
  • 34
  • 5