我知道有关此主题的两个不错的在线资源,XAML Guidelines和this less complete one。
我还是不太明白!
例如,假设我有两个项目:
在Wpf应用内部,我有三个资源协同工作,为不同的视图形成统一的方式,以提供错误反馈和关闭。其中两个资源通过DataTemplate提供:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="EditedStateIndicator.xaml" />
<ResourceDictionary Source="CloseCrossToggleButton.xaml" />
</ResourceDictionary.MergedDictionaries>
<DataTemplate x:Key="SatelliteViewClosePanelStyle" >
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource CloseCrossButtonStyle}" />
<Ellipse Style="{StaticResource EditedStateIndicatorStyle}" />
</StackPanel>
</DataTemplate>
这又可以在“SatelliteView.ResourceLibrary.xaml”中找到:
<!-- ##Satellite View Library-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="SatelliteViewClosePanel.xaml" />
<ResourceDictionary Source="InlineBorder.xaml" />
</ResourceDictionary.MergedDictionaries>
反过来又在“ControlLibrary.ResourceLibrary.xaml”中提供
<!-- ##Master Control Library reference-->
<ResourceDictionary.MergedDictionaries>
...
<ResourceDictionary Source="CustomControlStyles/SatelliteViewStyles/ResourceLibrary.xaml" />
...
</ResourceDictionary.MergedDictionaries>
然后在Wpf.App项目中使用,字面意思是App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Wpf.ControlLibrary;component/ResourceLibrary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
在应用程序内部是一个视图,它使用一些也需要访问控件库的内容:
<ResourceDictionary.MergedDictionaries>
Source="pack://application:,,,/SWpf.ControlLibrary;component/ResourceLibrary.xaml" />
</ResourceDictionary.MergedDictionaries>
<DataTemplate x:Key="AvatarEditingControlTemplate">
...
</DataTemplate>
干杯,
Berryl