silverlight-4.0resourcesprismstylesresourcedictionary

Error in Silverlight 4 + PRISM when a custom style is applied


The situation:

"Shell" project with App.xaml and a resource dictionary in Styles/Default.xaml with the interesting parts thus:

Default.xmal

<ResourceDictionary
  <Style x:Key="StandardTextBox" TargetType="TextBox">
  ...
  </Style>
</ResourceDictionary

App.xaml

<Application>
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Styles/Default.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>

In a module project I've got a form with:

<TextBox Style="{StaticResource StandardTextBox}" />

At runtime I get the infamous "Error HRESULT E_FAIL has been returned from a call to a COM component." exception. The funny thing is during design time, in VS, the style is applied just fine in design mode. (and how VS.Net works the magic of knowing there's a resource in App.xaml in the Shell project - which is not referenced by the module project AT ALL - is baffling ... but I digress)

My overall goal is to have resources defined in files separate from App.xaml, in the Shell project, and have the styles applied intrinsically across the Module projects.


Solution

  • The real issue was not including another referenced style. See this.