Home » Silverlight

Element is already the child / System.Windows.Markup.XamlParseException --> PivotControl Error

9. March 2011 by David 1 Comments

I have been working with Silverlight PivotViewer control and recently came across problem with the display of the control.  I have a solution with multiple projects one of which is a Silverlight application.  Everything would compile without any error.  When browsing to the form/page with the control I would immediately get an exception on the InitializeComponent(); method within the Silverlight UserControl.  This method is called before loading any pivot cxml data.

 

I have seen this component through odd errors or fail to load when there is javascript errors on the page or a failure of any ajax method.  The error that is thrown is as follows…

 

{System.Windows.Markup.XamlParseException: Set property 'System.Windows.FrameworkElement.Style' threw an exception. [Line: 15 Position: 43] ---> System.Windows.Markup.XamlParseException: Element is already the child of another element. [Line: 0 Position: 0]

   at MS.Internal.XcpImports.CreateFromXaml(UnmanagedMemoryStream stream, String sourceAssemblyName, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers)

   at System.Windows.Controls.Control.GetBuiltInStyle(IntPtr nativeTarget, IntPtr& nativeStyle)

   --- End of inner exception stack trace ---

   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)

   at PivotView.Viewer.InitializeComponent()

   at PivotView.Viewer..ctor()}

 

 

If searching Google you will see a number of posts on errors surrounding ‘XamlParseException’, ‘Styles’, ‘Element is already the child’ etc.  Without help from these posts, I finally came across the solution.  I found the error was the result of some missing references in the Silverlight project.  The components missing can be found in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Bin (which is installed as part of the most recent Silverlight Toolkit).  References to the following components was necessary.

 

System.Windows.Controls.Layout.Toolkit.dll
System.Windows.Controls.Toolkit.dll
System.Windows.Controls.Toolkit.Internals.dll

 

If you having issues, rename the xap file (adding .zip) and take a look to ensure those dlls are included.

 

I thought I would post this information for others as well as a reminder to myself.  If you have any questions, let me know.

 



PivotControl Error" trackback:ping="http://www.davidyardy.com/davidyardy/blog/trackback.axd?id=c9942ff6-a46f-4e8f-a8f3-5a8aca4a2220" /> -->

Comments (1) -

United States Stephen said:

I found that if an image path on a collection item is incorrect the Pivot Viewer throws a Silverlight exception:

Error: Unhandled Error in Silverlight Application
Code: 4009    
Category: ManagedRuntimeError      
Message: Element is already the child of another element.

Add comment



  Country flag
biuquote
  • Comment
  • Preview
Loading







Current HOT Blog List...

These are blog entries that I have found interesting and are worth checking out.
Forbidden