WPF 递归调用自动化对等 API 无效 [英] WPF Recursive call to Automation Peer API is not valid

查看:26
本文介绍了WPF 递归调用自动化对等 API 无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在加载包含组合框列的数据模板列的数据网格时,我收到错误消息对自动化对等 API 的递归调用无效".该错误最终被我们未处理的异常代码捕获.这似乎是我机器上的一个问题,谷歌没有提供解决问题的指导来源.这个问题似乎只发生在我用数据填充组合框时.填充组合框(如果我不加载数据)工作正常,并且在显示错误时我能够看到在后台正确检索的数据.

I am receiving an error message "Recursive call to Automation Peer API is not valid" when loading a datagrid with a datatemplatecolumn containing a combobox column. The error ends up caught in our unhandled exception code. This seems to be an issue on my machine, and google has provided no source of guidance on resolving the issue. The issue appears to only occur when I am populating the comboboxes with data. Populating the comboboxes (if I do not load data) works correctly, and while the error is displayed I am able to see the data properly retrieved in the background.

我正在使用 WPF 数据网格,其中我使用 DataGridTemplateColumn 在网格内添加组合框.我使用 objectdataprovider 将下拉列表绑定到枚举.在初始化屏幕时的后面代码中,我使用 Linq2Sql 语句来检索数据并填充网格的 Itemssource.

I am using a WPF datagrid where I'm using a DataGridTemplateColumn for adding a combobox inside the grid. I have the drop down list bound to an enum using an objectdataprovider. In the code behind when initializing my screen I use a Linq2Sql statement to retrieve data and populate the Itemssource of the grid.

<grid:DataGrid.Resources>
 <ObjectDataProvider
  x:Key="ChangeTypeData"
  MethodName="GetValues"
  ObjectType="{x:Type System:Enum}">
  <ObjectDataProvider.MethodParameters>
   <x:Type TypeName="namespace:ChangeType" />
  </ObjectDataProvider.MethodParameters>
 </ObjectDataProvider>     
    </grid:DataGrid.Resources>

 <grid:DataGrid.Columns>
 <grid:DataGridTextColumn Binding="{Binding DatapointName}" Header="Datapoint Changed" IsReadOnly="True" Width="Auto" />
 <grid:DataGridTemplateColumn Header="Change Type">
  <grid:DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
    <ComboBox
     Text="{Binding Path=ChangeTypeName}"
     ItemsSource="{Binding Source={StaticResource ChangeTypeData}}"
     Name="dgcboChangeType"
SelectionChanged="dgcboChangeType_SelectionChanged"/>
   </DataTemplate>
  </grid:DataGridTemplateColumn.CellTemplate>

感谢有关解决此问题的任何和所有指导.

Any and all guidance on solving this issue is appreciated.

推荐答案

我通过关闭网格控件上的自动化解决了这个问题.我发现这个问题是 WPF Toolkit 控件独有的,但是我在转换到 4.0 官方版本 DataGrid 时遇到了问题(与此问题无关.)

I've bypassed the problem on my end by turning off Automation on the grid control. I found that the problem was unique to the WPF Toolkit control, but I was having problems transitioning to the 4.0 official release DataGrid (unrelated to this question.)

因此,我从 WPFToolkit 派生该类并提供此覆盖:

So instead, I derive the class from the WPFToolkit and supply this override:

protected override AutomationPeer OnCreateAutomationPeer()
{
   return null;
}

也许有人可以告诉我们这是否是一个好主意.

Maybe someone can tell us if this is a good idea or not.

这篇关于WPF 递归调用自动化对等 API 无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆