问题
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