开发者

WPF Recursive call to Automation Peer API is not valid

开发者 https://www.devze.com 2023-01-21 03:35 出处:网络
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 u

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 gu开发者_开发知识库idance 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>

Any and all guidance on solving this issue is appreciated.


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.


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.


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.


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.


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.


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.


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;
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号