zoukankan      html  css  js  c++  java
  • WPF中添加一个文本输入框,按Enter回车,执行绑定的Command

    在WPF+WMMV模式中使用键盘和鼠标事件的绑定代码如下:

    <TextBox x:Name="SearchBox" Text="{Binding SearchText}" Width="246" Height="24" HorizontalAlignment="Right" PreviewKeyDown="SearchBox_OnKeyDown">
                 <TextBox.InputBindings>
                       <KeyBinding Command="{Binding KeyEventCommand}" Key="Enter"/>//绑定键盘输入事件

                <dxg:GridControl.InputBindings>

                    <MouseBinding Command="{Binding ProductDoubleClickCommand}" CommandParameter="{Binding ElementName=ProductCtrl,Path=CurrentItem}"

                                                                     MouseAction="LeftDoubleClick"/>//绑定鼠标事件

               </dxg:GridControl.InputBindings>

                 </TextBox.InputBindings>
     </TextBox>

    上面需要注意的是:搜索文本框的输入文本在按Enter后虽然会触发事件,但是获取不到搜索文本框的输入文本值,因此需要是搜索文本框的输入文本在按Enter后失去焦点,

    多以添加PreviewKeyDown="SearchBox_OnKeyDown,

     private void SearchBox_OnKeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Enter)
                {
                    SearchBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                }
            }

  • 相关阅读:
    带参数的装饰器
    python清空文件夹
    sqlalchemy的filter使用
    git pull命令的用法
    通过jenkins打包ipa包报错:Command CodeSign failed with a nonzero exit code(errSecInternalComponent)
    postman上传图片,及接口上传图片
    liunx中crontab没有生效
    liunx正则危险符号“*”星号
    rqalpha的改造工作
    Qt浅谈之一:内存泄露(总结)
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/7338187.html
Copyright © 2011-2022 走看看