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));
                }
            }

  • 相关阅读:
    POJ 1003 解题报告
    POJ 1004 解题报告
    POJ-1002 解题报告
    vi--文本编辑常用快捷键之光标移动
    常用图表工具
    September 05th 2017 Week 36th Tuesday
    September 04th 2017 Week 36th Monday
    September 03rd 2017 Week 36th Sunday
    September 02nd 2017 Week 35th Saturday
    September 01st 2017 Week 35th Friday
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/7338187.html
Copyright © 2011-2022 走看看