我最近将我的silverlight应用程序拆分为几个较小的项目。在单独的项目中引用资源字典
我已经感动了所有包含我的风格成为一个单独的项目资源字典(“Application.Themes”),然后我我的主要项目中引用这些从我的App.xaml文件。
这适用于主项目,但是所有引用这些资源字典中的样式的其他项目都会在设计器中将“对象引用未设置为对象的实例”异常引发,尽管它们编译和运行时没有任何问题用正确的风格。
我已经添加了一个App.xaml文件到每个引用相同的字典作为我的主要App.xaml文件的个别项目,这也没有什么区别。
是否有从另一个项目,允许设计者引用资源字典正确的方式来使用呢?
编辑:
下面是一些更多的信息和一些代码片段展示我有
我已经叫款式项目这个项目中“主题”的问题,我有几本词典是定义项目的所有样式。
在我的主要的App.xaml我有以下
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes;component/Styles/CoreStyles.xaml"/>
<ResourceDictionary Source="/Themes;component/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
如果我他们正常工作的主要项目中引用样式。然而,即使这些项目引用了主题项目,它们也不适用于任何其他项目。
我试图把每个用户控件的开始下面,以解决在设计时的风格,但它仍然无法解决风格是项目内。
<UserControl>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes;component/Styles/CoreStyles.xaml"/>
<ResourceDictionary Source="/Themes;component/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Additional Control Specific resources -->
</ResourceDictionary>
</UserControl.Resources>
<!-- The following resources are defined in Styles.XAML and don't resolve at design time and throw errors -->
<TextBlock Text="Header Test"
FontFamily="{StaticResource HeaderFontFamily}"
Foreground="{StaticResource StrongBrush}">
</UserControl>
我的styles.xaml看起来与此类似。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:behaviors="clr-namespace:Minerva.Presentation.Behavior;assembly=Minerva.Presentation"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
<SolidColorBrush x:Key="StrongBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.StrongColor}" />
<FontFamily x:Key="HeaderFontFamily">Segoe UI Light, Lucida Sans Unicode, Verdana</FontFamily>
</ResourceDictionary>
我真的不明白你在这里建议什么。我的主题项目已经在一个程序集中,并且已经被其他项目引用。 – Midimatt
我已经更新了有关项目结构的更多详细信息。 – Midimatt