gpt4 book ai didi

c# - 文本框输入键事件在 WPF 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 11:07:07 24 4
gpt4 key购买 nike

keydown 事件无法正常工作。当按下回车键时,我想引发与按钮相同的事件。这是 C#

    public partial class Search : Control
{
public SearchRevision()
{
InitializeComponent();
}


private void Button_Click_1(object sender, RoutedEventArgs e)
{
SearchViewModel vm = this.DataContext as SearchViewModel;
if (vm != null)
vm.Refresh();
}

private void myTextBox_KeyDown(Object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
SearchViewModel vm = this.DataContext as SearchViewModel;
if (vm != null)
vm.Refresh();
}
}

private void myTextBox_Escape(Object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
txtName.Text = "";
}
}
}

最佳答案

在 wpf 中没有 keycode 或 keys.enter相反,您可以使用:

private void myTextBox_KeyDown(Object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
SearchViewModel vm = this.DataContext as SearchViewModel;
if (vm != null)
vm.Refresh();
}
}

关于c# - 文本框输入键事件在 WPF 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15487902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com