C# 模拟单击datagrid标题列
我正在寻找并发现:,但我不知道我必须在“您的控制”中输入什么,我正在使用Silverlight 5,有人能帮我吗C# 模拟单击datagrid标题列,c#,wpf,silverlight,datagrid,C#,Wpf,Silverlight,Datagrid,我正在寻找并发现:,但我不知道我必须在“您的控制”中输入什么,我正在使用Silverlight 5,有人能帮我吗 DataGridColumnHeaderItemAutomationPeer peer = new DataGridColumnHeaderItemAutomationPeer (Your_control); 我的DataGrid是我的雇员 当我尝试使用它时,将其定义为: DataGridColumnHeaderItemAutomationPeer peer = new DataG
DataGridColumnHeaderItemAutomationPeer peer = new DataGridColumnHeaderItemAutomationPeer (Your_control);
我的DataGrid是我的雇员
当我尝试使用它时,将其定义为:
DataGridColumnHeaderItemAutomationPeer peer = new DataGridColumnHeaderItemAutomationPeer (dgEmployee);
系统发送给我一个错误:
“System.Windows.Automation.Peers.DataGridColumnHeaderAutomationPeer.DataGridColu的最佳重载方法匹配”mnHeaderAutomationPeer(System.Windows.Controls.Primitives.DataGridColumnHeader)“具有一些无效参数”
如何将dgEmployee的DataGridColumnHeader作为参数
谢谢 解决方案是:
System.Windows.Controls.Primitives.DataGridColumnHeader headerObj;
headerObj = GetColumnHeaderFromColumn(myDataGrid, myDataGrid.Columns[1].Header);
System.Windows.Automation.Peers.DataGridColumnHeaderAutomationPeer peer =
new DataGridColumnHeaderAutomationPeer(headerObj);
IInvokeProvider invoker = (IInvokeProvider)peer;
invoker.Invoke(); // Invoke a click programmatically
private System.Windows.Controls.Primitives.DataGridColumnHeader GetColumnHeaderFromColumn(DependencyObject parent, object header)
{
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
if (child != null)
{
if (child is System.Windows.Controls.Primitives.DataGridColumnHeader)
{
System.Windows.Controls.Primitives.DataGridColumnHeader columnHeader = child as System.Windows.Controls.Primitives.DataGridColumnHeader;
if (header.Equals(columnHeader.Content))
{
return columnHeader;
}
}
else
{
System.Windows.Controls.Primitives.DataGridColumnHeader columnHeader = GetColumnHeaderFromColumn(child, header);
if (null != columnHeader)
{
return columnHeader;
}
}
}
}
return null;
}
System.Windows.Controls.Primitives.DataGridColumnHeader headerObj;
headerObj=GetColumnHeaderFromColumn(myDataGrid,myDataGrid.Columns[1].Header);
System.Windows.Automation.Peers.DataGridColumnHeaderAutomationPeer=
新的DataGridColumnHeaderAutomationPeer(headerObj);
IInvokeProvider调用程序=(IInvokeProvider)对等方;
invoker.Invoke();//以编程方式调用单击
private System.Windows.Controls.Primitives.DataGridColumnHeader GetColumnHeaderFromColumn(DependencyObject父对象,对象头)
{
int count=VisualTreeHelper.GetChildrenCount(父级);
for(int i=0;i
可能对某些人有帮助,来自墨西哥似乎@SriramSakthivel中没有具有单个参数的构造函数,但当我尝试使用它时,系统向我发送了一个错误:“与'system.Windows.Automation.Peers.DataGridColumnHeaderAutomationPeer.DataGridColumnHeaderAutomationPeer.DataGridColumnHeaderAutomationPeer'匹配的最佳重载方法(System.Windows.Controls.Primitives.DataGridColumnHeader)“具有一些无效参数”那我怎么才能把我的DGemployee的DataGridColumnHeader放进去?错误是什么?用这个信息更新你的问题我不知道,但看起来它需要
DataGridColumnHeader
,你可以从column.Header
中得到它。@SriramSakthivel事实上,我是这样说的:DataGridColumn=(DataGridColumn)dPlantilla.SelectedItem;
System.Windows.Automation.Peers.DataGridColumnHeaderAutomationPeer=new DataGridColumnHeaderAutomationPeer(col.Header);
这就是我犯错误的时候