Silverlight 4 中的错误 +应用自定义样式时的 PRISM

发布于 2024-10-21 14:20:41 字数 1196 浏览 4 评论 0原文

情况:

“Shell”项目,包含 App.xaml 和 Styles/Default.xaml 中的资源字典,其中包含有趣的部分:

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>

在模块项目中,我有一个表单与:

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

在运行时,我收到臭名昭著的“错误 HRESULT E_FAIL 已从对 COM 组件的调用返回”。例外。有趣的是,在设计时,在VS中,样式在设计模式下应用得很好。 (VS.Net 如何发挥神奇作用,知道 Shell 项目中的 App.xaml 中有一个资源(模块项目根本没有引用该资源)令人费解……但我离题了)

我的总体目标是在 Shell 项目中,在与 App.xaml 分开的文件中定义资源,并在模块项目中固有地应用样式。

更新:是的,我在这里完全走上了错误的道路。 Blend 生成的 TextBox 样式引用了 ValidationToolTip 的另一种样式。如果不包含这一点,将会导致上述问题。不幸的是,错误消息毫无帮助,而且当 VS 中的波浪线下划线位于 XAML 定义中间深处且远离右侧时,很容易被忽略。生活和学习。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云仙小弟 2024-10-28 14:20:41

真正的问题是不包括另一个引用的样式。请参阅

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文