代码之家  ›  专栏  ›  技术社区  ›  gpanagopoulos

WPF ListBoxeEdit控件-以编程方式引发PageDown事件

  •  0
  • gpanagopoulos  · 技术社区  · 7 年前

    我在WPF中有一个ListBoxEdit-DevExpress控件,我想在单击另一个按钮时向下/向上翻页它的内容。

    当我尝试编程时,它失败了。下面是我的代码,其中DataSourceList是我的ListBoxEdit控件的x:Name。

    var presentationSource = PresentationSource.FromDependencyObject(this.DataSourceList);
    var args = new KeyEventArgs(Keyboard.PrimaryDevice, presentationSource, 0, Key.PageDown);
    
    args.RoutedEvent = Keyboard.KeyDownEvent;
    this.DataSourceList.RaiseEvent(args);
    

    1 回复  |  直到 7 年前
        1
  •  0
  •   gpanagopoulos    7 年前

    var child = this.DataSourceList.VisualChildren().FirstOrDefault(t => t.GetType() == typeof(ListBoxEditItem));
    if (child != null)
    {
           var args = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0,Key.PageDown);
           args.RoutedEvent = Keyboard.KeyDownEvent;
           args.Source = child;
           InputManager.Current.ProcessInput(args);
    }
    

    看来 this.DataSourceList.RaiseEvent(args);