[{"data":1,"prerenderedAt":220},["ShallowReactive",2],{"article-element-is-already-the-child-system-windows-markup-xamlparseexception-pivotcontrol-error":3},{"article":4,"tags":99,"previous":114,"next":163},{"id":5,"title":6,"author":7,"body":8,"createdAt":88,"description":89,"extension":90,"img":82,"meta":91,"navigation":92,"path":93,"seo":94,"stem":95,"tags":96,"updatedAt":88,"__hash__":98},"articles\u002Farticles\u002Felement-is-already-the-child-system-windows-markup-xamlparseexception-pivotcontrol-error.md","Element is already the child \u002F System.Windows.Markup.XamlParseException --> PivotControl Error","[object Object]",{"type":9,"value":10,"toc":85},"minimark",[11],[12,13,14,15,18,19,21,22,18,24,26,27,31,32,35,37,38,40,41,43,44,46,47,49,50,52,53,18,55,18,57,59,60,18,62,64,65,18,67,69,70,18,72,74,75,18,77,79],"p",{},"I have been working with Silverlight PivotViewer control and recently came across problem with the display of the control. \nI have a solution with multiple projects one of which is a Silverlight application.  Everything would compile without any error. \nWhen browsing to the form\u002Fpage with the control I would immediately get an exception on the InitializeComponent(); method within the Silverlight UserControl. \nThis method is called before loading any pivot cxml data.",[16,17],"br",{},"\n ",[16,20],{},"\nI 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. \nThe error that is thrown is as follows…",[16,23],{},[16,25],{},"\n{System.Windows.Markup.XamlParseException: Set property 'System.Windows.FrameworkElement.Style' threw an exception. ",[28,29,30],"span",{},"Line: 15 Position: 43"," ---> System.Windows.Markup.XamlParseException: Element is already the child of another element. ",[28,33,34],{},"Line: 0 Position: 0",[16,36],{},"\n   at MS.Internal.XcpImports.CreateFromXaml(UnmanagedMemoryStream stream, String sourceAssemblyName, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers)",[16,39],{},"\n   at System.Windows.Controls.Control.GetBuiltInStyle(IntPtr nativeTarget, IntPtr& nativeStyle)",[16,42],{},"\n   --- End of inner exception stack trace ---",[16,45],{},"\n   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)",[16,48],{},"\n   at PivotView.Viewer.InitializeComponent()",[16,51],{},"\n   at PivotView.Viewer..ctor()}",[16,54],{},[16,56],{},[16,58],{},"\nIf 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.",[16,61],{},[16,63],{},"\nSystem.Windows.Controls.Layout.Toolkit.dll\nSystem.Windows.Controls.Toolkit.dll\nSystem.Windows.Controls.Toolkit.Internals.dll",[16,66],{},[16,68],{},"\nIf you're having issues, rename the xap file (adding .zip) and take a look to ensure those dlls are included.",[16,71],{},[16,73],{},"\nI thought I would post this information for others as well as a reminder to myself.  If you have any questions, let me know.",[16,76],{},[16,78],{},[80,81],"img",{"src":82,"alt":83,"style":84},"\u002Farticles\u002Fimages\u002Fpivotviewer.jpg","","display:none;",{"title":83,"searchDepth":86,"depth":86,"links":87},2,[],"2015-04-20T08:07:13.7700000-04:00",null,"md",{},true,"\u002Farticles\u002Felement-is-already-the-child-system-windows-markup-xamlparseexception-pivotcontrol-error",{"title":6,"description":89},"articles\u002Felement-is-already-the-child-system-windows-markup-xamlparseexception-pivotcontrol-error",[97],"silverlight","MwzE74POWqzTSnbetCRmaz5deTYzJG440Jb4tLUMo7w",[100],{"id":101,"title":102,"body":103,"description":107,"extension":90,"img":108,"meta":109,"name":97,"navigation":92,"path":110,"seo":111,"stem":112,"__hash__":113},"tags\u002Ftags\u002Fsilverlight.md","Silverlight",{"type":9,"value":104,"toc":105},[],{"title":83,"searchDepth":86,"depth":86,"links":106},[],"Say no more.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fsilverlight",{"description":107},"tags\u002Fsilverlight","aLtzOSbx2leBhX5c__fGG4ZcqRvHO7p9rZCpLvRA0Bw",{"id":115,"title":116,"author":7,"body":117,"createdAt":154,"description":155,"extension":90,"img":156,"meta":157,"navigation":92,"path":158,"seo":159,"stem":160,"tags":161,"updatedAt":154,"__hash__":162},"articles\u002Farticles\u002Fchange-silverlight-class-library-to-application.md","Change Silverlight Class Library to Application",{"type":9,"value":118,"toc":152},[119,122,130,140,143,146,149],[12,120,121],{},"Add New Item to the Silverlight Class project > Silverlight Application Class (This adds app.xaml, app.xaml.cs files)",[12,123,124,125,129],{},"Open the class library project file and change ",[126,127,128],"silverlight-application",{},"false","\nto true (Unload the class library project and edit the csproj file)",[12,131,132,133],{},"Add new element XapOutputs to project file below the element",[126,134,135,136],{}," i.e. add ",[137,138,139],"xap-outputs",{},"true",[12,141,142],{},"Now open Project Properties of the Silverlight Class library and change to the > Silverlight tab > Change the starter object",[12,144,145],{},"Change the following Project Property > Silverlight tab > Set the Xap file name",[12,147,148],{},"In the related web application add project property > Silverlight tab > Add your Silverlight application",[12,150,151],{},"You have not changed a Silverlight class library to an application project where the xap will be output and copied to the respective web site ClientBin directory.",{"title":83,"searchDepth":86,"depth":86,"links":153},[],"2015-04-20T08:07:13.8700000-04:00","Changing class library type to application.","\u002Farticles\u002Fimages\u002Fm8gdjJD1VK.png",{},"\u002Farticles\u002Fchange-silverlight-class-library-to-application",{"title":116,"description":155},"articles\u002Fchange-silverlight-class-library-to-application",[97],"u_COjDxXgW8q1CXFUEeyO_rqVp2EzKopDX8j3mKRw2Y",{"id":164,"title":165,"author":7,"body":166,"createdAt":211,"description":212,"extension":90,"img":208,"meta":213,"navigation":92,"path":214,"seo":215,"stem":216,"tags":217,"updatedAt":211,"__hash__":219},"articles\u002Farticles\u002Fnamespace-your-javascript.md","Namespace your JavaScript",{"type":9,"value":167,"toc":209},[168,176,180,183,187,206],[12,169,170,171,18,173,175],{},"There are a couple of ways to create namespaces for your code.  This format allows you to intentionally expose functions as public or keep them internal\u002Fprivate.  I like the following version…",[16,172],{},[16,174],{},"\nvar mynamespace = new function () {",[177,178,179],"blockquote",{},"  \nvar internalFunction = function() { \n     \u002F\u002FTODO: code \n};  \n",[177,181,182],{},"  \nthis.publicFunction = function() { \n    \u002F\u002FTODO: code \n};  \n",[184,185,186],"strong",{},"Simple, now why the heck do this?",[188,189,190,194,197,200,203],"ul",{},[191,192,193],"li",{},"A namespace is a container and allows you to bundle up all your functionality using a unique name",[191,195,196],{},"In JavaScript a namespace is really just an object that you have attached all further methods, properties and objects",[191,198,199],{},"Without the usage of namespaces every function will be in the global (aka window) namespace (this occurs by default if you do not use a namespace).  It is a good practice not to clutter the global namespace",[191,201,202],{},"Using namespaces prevents the overwriting of existing function names",[191,204,205],{},"Using namespaces is one step in the direction of object-oriented which promotes modularity and code re-use",[80,207],{"src":208,"alt":83,"style":84},"\u002Farticles\u002Fimages\u002Fns.png",{"title":83,"searchDepth":86,"depth":86,"links":210},[],"2015-04-20T08:07:13.6900000-04:00","How to use namespaces within your JavaScript",{},"\u002Farticles\u002Fnamespace-your-javascript",{"title":165,"description":212},"articles\u002Fnamespace-your-javascript",[218],"javascript","hpUwRZUyAy5HzKNcCB4a57Dnyk7v34btaAKN8B18S4o",1781574766896]