【发布时间】:2012-05-30 20:23:58
【问题描述】:
我的 app.xaml 中有一堆样式,它们都在我的 SL5 应用程序的页面中使用得很好。我想将这些样式移动到多个资源字典中,使其更易于管理和使用。
首先,我将样式复制到项目中 /Styles/ButtonStyles.xaml 页面中的新资源字典中... sn-p 如下所示:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="RegistrationsRolloverImage" TargetType="Button">
<Setter Property="Template">...</Setter>
</Style>
<Style x:Key="FinancialLedgerRolloverImage" TargetType="Button">
<Setter Property="Template">...</Setter>
</Style>
</ResourceDictionary>
接下来,我将以下内容添加到我的 App.xaml:
<ResourceDictionary x:Key="MergedStyles">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/ButtonStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
它迫使我在 ResourceDictionary 标记中添加一个 x:key,因为我不断收到构建错误。现在它构建了,但是使用该样式的按钮没有获得该样式。事实上,我收到了一个 JS 错误,它在我的资源字典中找不到具有两种样式名称的样式。如果它们在 App.xaml 中,它们就可以正常工作,但如果它们在单独的资源字典中,则不能。我反映了生成的 DLL,可以看到 DLL 中的样式/buttonstyles.xaml。
不知所措......并且无法弄清楚出了什么问题。想法?
【问题讨论】:
-
你能在某处发布完整的
App.xaml吗?因为它应该可以工作并且您不需要向您的ResourceDictionary添加密钥...也许您已经在ResourceDictionary中 -
同意...令人困惑的是它应该可以正常工作。这是整个 app.xaml:pastebin.com/iakhFULy
标签: silverlight styles resourcedictionary