WPF 응용 프로그램에서 키를 입력 할 때마다 텍스트 상자의 내용을 가져 오려고합니다. 그러나 KeyPress에 대한 옵션이 없습니다. KeyDown 이벤트를 사용했습니다. 모든 키 누르기에 대한 코드 뒤에 있습니다. 효율적인 대안이 있습니까? 여기에 대신 직접 텍스트 상자 퍼팅의 Keypress 이벤트가 눌려진 키를 확인합니다
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; }
}
내 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>
확인이 : http://msdn.microsoft.com/en-us/library/ms752054.aspx – JohnLBevan
나는 same.My 질문 난 내 코드 숨김에서 중단 점을 때 실제로 동안 그 관찰하고 한 각 키를 누르면 컨트롤이 서버 페이지로 이동하고 프로세스가 실행됩니다. 어떻게하면이 @@@ 서버 페이지 – Suresh
을 막을 수 있습니까? - 네가 무슨 말하는지 모르겠다. ViewModel의 Command에 대해 InputBinding이 필요합니다. 코드에서 절차 적으로 처리하는 것이 아닙니다. –