How to simulate the user click on a column header

2019-06-04 23:26发布

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条回答
淡お忘
2楼-- · 2019-06-04 23:59

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
查看更多
登录 后发表回答