title: Changing/Adding Resource Dictionary in code behind, Please help
body: <p>I'm am currently developing a silverlight application, I am still a beginner with this.
  I am wondering if it is possible to change the resource dictionary's source in code behind(C#)
  within the App.xaml?
  I have tried the code below, but get an exception, i am getting the style folder name from a WCF Service, the variable is called Style(this contains the name of the folder) </p>
  
  <pre><code>ResourceDictionary rDictionary = this.Resources.MergedDictionaries[0];
          rDictionary.Source = new Uri(string.Format("Resources/Styles/{0}/Styles.xaml", style), UriKind.Relative);
          this.Resources.MergedDictionaries.Add(rDictionary);
  </code></pre>
  
  <p>I'm getting an error at </p>
  
  <pre><code>rDictionary.Source = new Uri(string.Format("Resources/{0}/Styles.xaml", "Default"), UriKind.RelativeOrAbsolute);
  </code></pre>
  
  <p>Which reads </p>
  
  <pre><code>System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
     at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
     at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, String s)
     at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
     at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
     at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry&amp; newEntry, Object newValue)
     at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, ValueOperation operation)
     at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
     at System.Windows.ResourceDictionary.set_Source(Uri value)
     at FCStarFish.App..ctor()
  </code></pre>