简体   繁体   English

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

[英]WPF ListBoxEdit control - Raise PageDown event programmatically

I ve got a ListBoxEdit DevExpress control in WPF and I want to page down / page up its contents when clicking another button. 我在WPF中有一个ListBoxEdit DevExpress控件,当我单击另一个按钮时,我想向下/向上翻页其内容。

In the UI, when I focus on the ListBoxEdit control and key PageDown it works. 在用户界面中,当我专注于ListBoxEdit控件和键PageDown时,它将起作用。

When I try programmatically it fails. 当我以编程方式尝试时,它会失败。 My code is below where DataSourceList is the x:Name of my ListBoxEdit control. 我的代码在下面,其中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);

Any idea what am I doing wrong? 知道我在做什么错吗?

I found it :) 我找到了 :)

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

It seems that this.DataSourceList.RaiseEvent(args); 似乎this.DataSourceList.RaiseEvent(args); didn't do the the trick, while the Source of the event has to be the ListBoxEditItem rather than the ListBoxEdit control. 并没有解决问题,而事件的源必须是ListBoxEditItem而不是ListBoxEdit控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM