WP7 Enter an enter key to send text from text field to text block

Hey guys, after the tutorial shows how to take text from a text field and display it in a text block when the user clicks a button. Simple enough ... but I want to do this instead of pressing a button that adds the text that I want the enter button to do this.

Searching here, I found the following code, but it does nothing.

private void textBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            listBox.Items.Add(textBox.Text);
        }
    }

So, a text box with a string is called a text box, and I want the text from this text box to be added to my list (listBox). When I press the enter button, it does nothing. Any help?

Thank!

+3
4

, , .

:

. :

<ListBox Height="276" HorizontalAlignment="Left" Margin="14,84,0,0" Name="listBox1" VerticalAlignment="Top" Width="460" />

:

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        this.listBox1.Items.Add(textBox1.Text);
    }
}
+6

KeyDown, . "" , - , VS , .

+1

@Court from the answer you gave @Trees, I can assume that you are really not sure if it is connected KeyDown. Do you have the following code in the XAML file?

<TextBox Height="32" HorizontalAlignment="Left" Margin="13,-2,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="433" KeyDown="textBox1_KeyDown" />

@Matt Lacey intercepts Enter from PC keyboard also works

0
source

It looks like you need to handle the KeyUp event.

0
source

Source: https://habr.com/ru/post/1758561/


All Articles