我的 app.xaml 中有很多样式,它们都在 SL5 应用程序的页面中使用得很好。我想将这些样式移至多个资源词典,以使其更易于管理和使用。
首先,我将样式复制到项目中 /Styles/ButtonStyles.xaml 页面中的新资源字典中...片段如下所示:
<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中的styles/buttonstyles.xaml。
茫然……不知道出了什么问题。有想法吗?
他们在同一个项目中吗?在你的 app.xaml 中尝试更多类似的东西;
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/YourResDictionaryContaining.Proj.Name;component/Styles/ButtonStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我必须这样做才能将资源字典存储在一个项目中,然后将其添加到每个其他项目的 app.xaml 中,以使它们在全球范围内可用。目前,我以这种方式在同一个解决方案中运行了 20 个项目中的大约 6 个资源字典,效果非常好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)