Determining the Enter key is pressed in a TextBox

前端 未结 5 1327
无人共我
无人共我 2021-02-02 07:08

Consider a XAML TextBox in Win Phone 7.

  

The goal here is that when the user presses the Enter

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-02 07:32

    You'll be looking to implement the KeyDown event specific to that textbox, and checking the KeyEventArgs for the actual Key pressed (and if it matches Key.Enter, do something)

    
    
    private void Box_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key.Equals(Key.Enter))
        {
            //Do something
        }
    }
    

    Just a note that in the Beta version of the WP7 emulator, although using the software on-screen keyboard detects the Enter key correctly, if you're using the hardware keyboard (activated by pressing Pause/Break), the Enter key seems to come through as Key.Unknown - or at least, it was doing so on my computer...

提交回复
热议问题