title: Troubleshooting a Silverlight Exception on the Pivot Control (System.Windows.FrameworkElement.Style)
body: <p>I'm having a somewhat maddening issue just trying to get the Silverlight Pivot Control to work out of the box.</p>
  
  <p>When I wire everything together, I see this stack trace in the JavaScript errors:</p>
  
  <pre><code>Unhandled Error in Silverlight Application Set property 'System.Windows.FrameworkElement.Style' threw an exception. [Line: 9 Position: 35]   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
     at VehiclePivotViewer.MainPage.InitializeComponent()
     at VehiclePivotViewer.MainPage..ctor(IDictionary`2 initParams)
     at VehiclePivotViewer.App.Application_Startup(Object sender, StartupEventArgs e)
     at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
     at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  </code></pre>
  
  <p>I actually downloaded a helper library to dig further into that exception, and it looks like it's <strong>having a hard time with the MainPage.xaml markup</strong>, even though it all appears to be valid.</p>
  
  <hr>
  
  <p>If it's helpful, I've listed the steps I took to set it all up below.</p>
  
  <ol>
  <li>Create a new MVC3 web application</li>
  <li>Create a Silverlight 4 application project in the same solution, and add it to the web project</li>
  <li>Add the five <code>System.Windows.Pivot</code> assembly references</li>
  <li><p>Add the control to my MainPage.xaml</p>
  
  <p></p>
  
  <pre><code>&lt;Grid x:Name="LayoutRoot" Background="White"&gt;
      &lt;Pivot:PivotViewer x:Name="Viewer" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p></li>
  <li><p>Wire up the collection URL: <code>Viewer.LoadCollection(initParams["CollectionUrl"], null);</code></p></li>
  <li>Set the appropriate values in the view:</li>
  </ol>
  
  <p>`</p>
  
  <pre><code>&lt;div id="silverlightControlHost"&gt;
      &lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"&gt;
          &lt;param name="source" value="ClientBin/xxxPivotViewer.xap"/&gt;
          &lt;param name="onError" value="onSilverlightError" /&gt;
          &lt;param name="background" value="white" /&gt;
          &lt;param name="minRuntimeVersion" value="4.0.50826.0" /&gt;
          &lt;param name="autoUpgrade" value="true" /&gt;
          &lt;param name="enableHtmlAccess" value="true" /&gt;
            &lt;param name="initParams" value="collectionUrl=@ViewBag.CollectionUrl %&gt;" /&gt;
          &lt;a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50826.0" style="text-decoration:none"&gt;
              &lt;img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/&gt;
          &lt;/a&gt;
      &lt;/object&gt;&lt;iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"&gt;&lt;/iframe&gt;&lt;/div&gt;
  </code></pre>
  
  <p>`</p>
  
  <p>Anyone have any thoughts or suggestions?  I'm extremely new to Silverlight, and am kinda sorta pulling my hair out.</p>