从Nuget包中的资源合并资源字典

时间:2015-11-30 16:26:34

标签: xaml uwp

所以我在另一个程序集中有一个资源字典。它看起来像这样:

<ResourceDictionary
Source="ms-appx:///MyStuff.UI.Common/Styles/Shared.xaml" />

我正在尝试删除项目引用并使用nuget包添加引用。在我这样做之后,我得到以下运行时错误:

Failed to assign to property 'Windows.UI.Xaml.ResourceDictionary.Source' because the type 'Windows.Foundation.String' cannot be assigned to the type 'Windows.Foundation.Uri'. [Line: 12 Position: 37]

如何在一个单独的程序集中将此资源字典合并到一个nugget包中?我认为没有区别。

1 个答案:

答案 0 :(得分:0)

XAML Merged Dictionaries比它们看起来更棘手。如果您引用本地项目,那么一切都很好,然后您的ResourceDictionary Source =路径。

如果您正在引用外部DLL(不在解决方案中),引用的DLL文件夹也必须包含所有* .xml,* .xr.xml,* .xbf,* .jpg / png / gif等。< / p>

当我将解决方案项目迁移到外部DLL引用时,我有主要 Source = Uri语法问题。另外,我引用的DLL文件夹没有正确文件夹中的所有资源文件。

我遵循的程序是:1。引用DLL包含合并的词典(XAML样式表)。 2.确保参考路径包含所有必需文件。 3.将合并的字典引用添加到App.xaml

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="ms-appx:///NAMESPACE_HERE/Styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

这个PostBuild.bat文件描述了我如何在成功构建时复制所有必需的文件:

Echo Starting: PostBuildEvent: Call $(ProjectDir)PostBuild.Bat $(ProjectDir) $(OutDir) $(TargetPath) $(RootNameSpace)
Echo With Parameters: %1 %2 %3 %4

REM ***
REM *** Variables
REM ***
SET BuildLocationBin=..\..\..\..\..\..\..\..\bin

REM ***
Echo *** Publish to Bin
REM ***
MD %BuildLocationBin%
%WINDIR%\system32\attrib.exe %BuildLocationBin%\*.* -r /s
%WINDIR%\system32\xcopy.exe %1Properties\*.rd.xml %BuildLocationBin%\%4\Properties\*.* /s/r/y
%WINDIR%\system32\xcopy.exe %1%2*.png %BuildLocationBin%\%4\*.* /s/r/y
%WINDIR%\system32\xcopy.exe %1%2*.xbf %BuildLocationBin%\%4\*.* /s/r/y
%WINDIR%\system32\xcopy.exe %1%2*.xml %BuildLocationBin%\%4\*.* /s/r/y
%WINDIR%\system32\xcopy.exe %3 %BuildLocationBin%\*.* /s/r/y
%WINDIR%\system32\xcopy.exe %1%2*.pri %BuildLocationBin%\*.* /s/r/y

Echo *** Postbuild Complete ***

希望这有帮助!

相关问题