How to simulate the user click on a column header of a datagrid in WPF?

不羁岁月 提交于 2019-12-10 11:48:59

问题


I need to simulate thru code the user clicking on a header of a WPF datagrid column (using .Net 4 in case it matters).

Is this possible?


回答1:


I think you can use the AutomationPeer classes, which are designed for this sort of thing, specifically the DataGridColumnHeaderItemAutomationPeer Class.

 DataGridColumnHeaderItemAutomationPeer peer = new DataGridColumnHeaderItemAutomationPeer (Your_control);
 IInvokeProvider invoker= (IInvokeProvider)peer;
 invoker.Invoke(); // Invoke a click programmatically


来源:https://stackoverflow.com/questions/9400714/how-to-simulate-the-user-click-on-a-column-header-of-a-datagrid-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!