我最近將我的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