Silverlight:从另一个项目添加资源字典

时间:2011-11-13 22:54:07

标签: silverlight xaml

我在项目A中有一个XAML资源字典。如何将它合并到项目B中的资源字典中?

2 个答案:

答案 0 :(得分:1)

其中Granite.Xaml是库,ConvertersList.xaml已被标记为资源。

<ResourceDictionary Source="/Granite.Xaml;component/ConvertersList.xaml" />

这是资源字典的内容。请注意,即使转换器与字典位于同一项目中,我也必须在命名空间声明中包含程序集名称。如果您不这样做,您将获得运行时异常。

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:Granite.Xaml.Converters;assembly=Granite.Xaml"
    >

    <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
    <converters:DebugBreakConverter x:Key="DebugBreakConverter" />
    <converters:DebugTraceConverter x:Key="DebugTraceConverter" />
    <converters:DictionaryConverter x:Key="DictionaryConverter" />
    <converters:MaxLengthToBoolTrueConverter x:Key="MaxLengthToBoolTrueConverter" />
    <converters:MinLengthToBoolTrueConverter x:Key="MinLengthToBoolTrueConverter" />
    <converters:NotBoolToVisibilityConverter x:Key="NotBoolToVisibilityConverter" />
    <converters:NotConverter x:Key="NotConverter" />
    <converters:NotNullToBooleanConverter x:Key="NotNullToBooleanConverter" />
    <converters:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter" />
    <converters:NotZeroToBooleanConverter x:Key="NotZeroToBooleanConverter" />
    <converters:NotZeroToVisibilityConverter x:Key="NotZeroToVisibilityConverter" />
    <converters:NullToBooleanConverter x:Key="NullToBooleanConverter" />
    <converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
    <converters:StringToBooleanConverter x:Key="StringToBooleanConverter" />
    <converters:StringToLowerConverter x:Key="StringToLowerConverter" />
    <converters:StringToUpperConverter x:Key="StringToUpperConverter" />
    <converters:ZeroToBooleanConverter x:Key="ZeroToBooleanConverter" />
    <converters:ZeroToVisibilityConverter x:Key="ZeroToVisibilityConverter" />

</ResourceDictionary>

答案 1 :(得分:0)

这对我有用:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Namespace.From.Your.Dll;component/Style.xaml"/>      
</ResourceDictionary.MergedDictionaries>