开发者

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 i开发者_StackOverflow中文版nfamous "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.

Update: Yeah, I was totally on the wrong war path here. The TextBox style that Blend generates references another style for the ValidationToolTip. Failing to include that will cause the issue described above. Unfortunately the error message was quite unhelpful and the squiggle underline in VS is easily missed when it's deep in the middle of the XAML definition and way off to the right. Live and learn.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜