【发布时间】:2018-06-06 19:40:24
【问题描述】:
如何将此代码更改为主动检测我的键盘。现在它显示了我按回车后写的内容。我怎样才能显示我可以在没有输入键的情况下写什么。
XAML:
<StackPanel>
<TextBlock Width="300" Height="20">
Type some text into the TextBox and press the Enter key.
</TextBlock>
<TextBox Width="300" Height="30" Name="textBox1"
KeyDown="OnKeyDownHandler"/>
<TextBlock Width="300" Height="100" Name="textBlock1"/>
</StackPanel>
C#:
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
textBlock1.Text = "You Entered: " + textBox1.Text;
}
}
或者也许是一些不同的方法来创建它?
【问题讨论】:
-
嗯……你想做什么?!因为这不会保存您之前输入的内容...
标签: c# wpf keyboard key detection