WPF 对 Automation Peer API 的递归调用无效

发布于 2024-09-28 23:33:56 字数 1842 浏览 3 评论 0原文

我收到一条错误消息

“对 Automation Peer API 的递归调用无效”

  • 加载带有包含 combobox 列的 datatemplatecolumndatagrid 时。该错误最终被我们未处理的异常代码捕获。这似乎是我的机器上的一个问题,谷歌没有提供解决该问题的指导来源。该问题似乎仅在我用数据填充组合框时才会出现。

  • 填充组合框(如果我不加载数据)可以正常工作,并且在显示错误时我可以看到在后台正确检索的数据。

  • 我正在使用 WPF 数据网格,其中使用 DataGridTemplateColumn网格内添加组合框 >。我使用 objectdataprovider 将下拉列表绑定到 enum

  • 在初始化屏幕时的代码中,我使用 Linq2Sql 语句来检索数据并填充网格的 Itemssource

    <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>
</grid:DataGridTemplateColumn>
<grid:DataGrid.Columns>

感谢任何有关解决此问题的指导。

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.

  • 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>
</grid:DataGridTemplateColumn>
<grid:DataGrid.Columns>

Any and all guidance on solving this issue is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

哽咽笑 2024-10-05 23:33:56

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

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

protected override AutomationPeer OnCreateAutomationPeer()
{
   return null;
}

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

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.)

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.

救星 2024-10-05 23:33:56

我有完全相同的错误。然而对我来说,奇怪的是,同一个应用程序在我的笔记本电脑上运行良好,却在我的台式电脑上导致了错误。相同的操作系统、相同的架构、相同的 Visual Studio 以及相同的附加组件。

因此,我检查了笔记本电脑上对 WPFToolkit 的引用,一切正常。它指向:

C:\Program Files (x86)\WPF Toolkit\v3.5.40619.1\WPFToolkit.dll

然后我检查了桌面上的参考,它指向:

C:\Program Files (x86)\WPF Toolkit\v3.5.50211.1\WPFToolkit.dll

如您所见,我安装了两个不同版本的 WPFToolkit。我将整个文件夹从笔记本电脑复制到桌面,将引用从版本 v3.5.50211.1 更改为 v3.5.40619.1,问题得到解决。没有更多的例外。希望这也会对某人有所帮助。

I had exactly the same error. However for me it was strange that the same application was working fine on my laptop and caused the error on my desktop PC. The same OS, the same architecture and the same Visual Studio with the same add-ons.

So I checked references to WPFToolkit on my laptop, where everything was fine. It pointed to:

C:\Program Files (x86)\WPF Toolkit\v3.5.40619.1\WPFToolkit.dll

then I checked reference on my desktop, it pointed to:

C:\Program Files (x86)\WPF Toolkit\v3.5.50211.1\WPFToolkit.dll

As you can see I had two different versions of WPFToolkit installed. I copied whole folder from my laptop to my desktop, changed references from version v3.5.50211.1 to v3.5.40619.1 and the problem was resolved. No more exceptions. Hope this will help someone as well.

我不是你的备胎 2024-10-05 23:33:56

我在 NET 3.5 中使用 WPFToolkit DataGrid 遇到了同样的问题。

我已将 WPFToolkit DataGrid 绑定到 EntityFramework ObservableCollection,其中实体的层次结构具有两种方式关联(Parent<->Items)。

我通过在 DataGrid 上禁用隐式启用的 AutoGenerateColumns 并手动设置列来解决该问题。

希望这有帮助。

I was getting the same problem in NET 3.5 with WPFToolkit DataGrid.

I have bound my WPFToolkit DataGrid to EntityFramework ObservableCollection, with hierarchy of entities that have two way associations (Parent<->Items).

I solved the issue by disabling implicitly enabled AutoGenerateColumns on the DataGrid, and manually setting the columns.

Hope this helps.

暗恋未遂 2024-10-05 23:33:56

我遇到了同样的问题 - 您使用的是 WPFToolkit 中的数据网格,还是 .NET 4.0 附带的数据网格。我们仍然在这里使用工具包之一。

另外,我注意到通过远程桌面使用该应用程序时不会出现此问题。

的问题:

http://wpf.codeplex.com/workitem/14443

此处发布了类似 解决方案。还没有机会尝试一下。

I'm getting the same problem - are you using the datagrid from the WPFToolkit, or the one that ships with .NET 4.0. We're still using the toolkit one here.

Also, I've notice that this problem does not occur when using the app through remote desktop.

Similar problem posted here:

http://wpf.codeplex.com/workitem/14443

With a proposed solution. Haven't had a chance to try it.

爱你不解释 2024-10-05 23:33:56

我也有同样的问题。所以我还检查了对 WPFToolkit 的引用。我安装了两个相同版本的 WPFToolkit(版本 v3.5.50211.1),但仅在我的笔记本电脑上可以正常工作。

因此,我将旧版本 v3.5.40619.1 放在我的 Windows Embedded Standard 7 PC 上,没有更多例外。

所以我得出的结论是,在某些情况下较新版本的运行系统存在一些问题。

I also had the same problem. So I checked also the reference to the WPFToolkit. I had two same versions of WPFToolkit installed (Version v3.5.50211.1), but only on my Laptop works it fine.

So I put the older version v3.5.40619.1 on my Windows Embedded Standard 7 PC and no more exceptions.

So I came to the conclusion that in some cases the newer Version has some problems with the runing system.

心舞飞扬 2024-10-05 23:33:56

您好,当我使用 WPF 应用程序运行 Microsoft 测试管理器时,我也遇到了同样的问题。我们使用的是WPFtoolkit版本v3.5.50211.1,用较低版本v3.5.40619.1替换WPF工具包已经解决了这个问题。

现在我们可以同时运行 MTM 工具和 WPF 应用程序。

在 WPFToolkit v3.5.50211.1 中,修复了与 UI 自动化相关的一个错误,我猜是因为在使用最新的 WPFtoolkit 时会出现此自动化对等问题。

Hi I also had same problem when I am running Microsoft Test Manager with our WPF application. We were using the WPFtoolkit version v3.5.50211.1, replacing WPF toolkit with lower version v3.5.40619.1 has solved this problem.

Now we are able to run the MTM tool and WPF application both simultaneously.

In WPFToolkit v3.5.50211.1 one bug is fixed related to UI Automation and I guess because of that this automation peer issue is coming while using the latest WPFtoolkit.

情话已封尘 2024-10-05 23:33:56

我能够通过使用以下两个派生类替换 WPF XAML 文件中的 DataGrid 和 ComboBox 来解决此问题,这两个派生类都重写 OnCreateAutomationPeer() 方法。

public class SafeDataGrid : DataGrid
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return null;
    }
}

public class SafeComboBox : ComboBox
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return null;
    }
}

I was able to fix this issue by replacing both the DataGrid and the ComboBox in the WPF XAML file with the following two derived classes which both override the OnCreateAutomationPeer() method.

public class SafeDataGrid : DataGrid
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return null;
    }
}

public class SafeComboBox : ComboBox
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return null;
    }
}
坠似风落 2024-10-05 23:33:56

我在旧的解决方案上遇到了同样的问题(尽管它在我的本地开发计算机上工作正常,但在测试系统上失败(使用 WPFToolkit 3.5.50211.1)

原来我的本地开发计算机有一个旧的 WPFToolkit:3.5.40128.1

然而,我做了更多检查,意识到问题仅当 DataGrid 是 Microsoft.Windows.Controls.DataGrid(即 WPFToolkit 之一)时出现,并且它包含来自 System.Windows.Controls 命名空间的控件(在此案例 ComboBox) - 以及来自 .Net PresentationFramework.dll )

我们已将解决方案从 .Net 4.5.1 更新到 .Net 4.7.1 ->这意味着新版本的PresentationFramework.dll,但WPFToolkit dll 没有改变。

确定解决此问题的最佳方法是仅删除 WPFToolkit.dll 引用,并将所有 DataGrid 从 Microsoft.Windows.Controls.DataGrid 更新为较新的 System.Windows.Controls.Datagrid。

I had this same problem crop up on an older solution (although it was working fine on my local dev computer, but failing on the test system (with WPFToolkit 3.5.50211.1)

Turned out my local dev computer had an older WPFToolkit: 3.5.40128.1

However I did a little more checking around and realised that the problem was only when the DataGrid was a Microsoft.Windows.Controls.DataGrid (ie a WPFToolkit one), and it contained a control from the System.Windows.Controls namespace (in this case a ComboBox) - and from the .Net PresentationFramework.dll )

We'd updated the solution to .Net 4.7.1 from .Net 4.5.1 -> which would have meant a new version of the PresentationFramework.dll, but the WPFToolkit dll had not changed.

Decided that the best way to fix this was to just remove the WPFToolkit.dll reference, and update all the DataGrids from Microsoft.Windows.Controls.DataGrid to the newer System.Windows.Controls.Datagrid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文