Am trying to get the content of a textbox whenever enter key is pressed in WPF application.But there is no option for KeyPress.So i used KeyDown event.But each time the control goes to the code behind for every keypress.Is there any efficient alternate for this ?
private void txt_chat_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
txt_conversation.AppendText(Environment.NewLine+txt_chat.Text);
}
else { return; }
}
and my XAML
<RichTextBox IsReadOnly="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
x:Name="txt_conversation"
HorizontalAlignment="Left"
Height="150"
Margin="21,21,0,0"
VerticalAlignment="Top"
Width="269">
<FlowDocument>
<Paragraph>
<Run Text="RichTextBox" />
</Paragraph>
</FlowDocument>
</RichTextBox>
<TextBox ScrollViewer.VerticalScrollBarVisibility="Auto"
KeyDown="txt_chat_KeyDown_1"
x:Name="txt_chat"
HorizontalAlignment="Left"
Height="84"
Margin="51,190,0,0"
VerticalAlignment="Top"
Width="209">
</TextBox>