Xaml Windows 10通用合并词典
因此,我有一个Windows通用类库,其中有一个资源字典,我想在App.xaml中与我的Windows 10通用应用程序的主资源字典合并 我的App.xaml只是从同一程序集合并到我的主资源字典中Xaml Windows 10通用合并词典,xaml,uwp,Xaml,Uwp,因此,我有一个Windows通用类库,其中有一个资源字典,我想在App.xaml中与我的Windows 10通用应用程序的主资源字典合并 我的App.xaml只是从同一程序集合并到我的主资源字典中 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
关于Windows 8.x应用商店应用这似乎是它应该如何工作的。但它仍然不起作用
而这个
<ResourceDictionary Source="ms-appx:///{AssemblyName}/Shared.xaml" />
<ResourceDictionary Source="pack://application:,,,/{AssemblyName};component/Shared.xaml" />
(我知道这是WPF的方式,但我想无论如何我都会尝试一下!)
但似乎都不管用
我在应用程序程序集中拥有的资源字典的生成操作设置为“Page”。这些资源字典仅在合并中使用以下内容:
<ResourceDictionary Source="Styles/Styles.xaml"/>
我得到了以下神秘的错误:
未能分配给属性
“Windows.UI.Xaml.ResourceDictionary.Source”,因为类型
“Windows .Field.String”不能被分配给类型
“窗户.基金会. Uri .”[行:12位置:37]
正如Romasz在评论中提到的,您需要参考包含样式的项目。然后使用下面的代码进行参考
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///UserControlLibs/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
XAML合并词典比看起来更复杂。如果您引用的是本地项目,那么您的源=路径就很好了
如果引用的是外部DLL(不在解决方案中),则引用的DLL文件夹还必须包含所有*.xml、*.xr.xml、*.xbf、*.jpg/png/gif等
我遵循的程序是:
1.包含合并字典(XAML样式表)的引用DLL。
2.确保引用路径包含所有必需的文件。
3.将合并字典引用添加到App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///NAMESPACE_HERE/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
希望这有帮助 您是否添加了库作为项目的参考?我正在使用
,它似乎可以正常工作。您如何将此资源字典添加到合并字典中?然后会发生什么?是的,{AssemblyName}被添加为对我的应用程序的项目的引用:)你们在另一个程序集中的资源字典上设置了什么构建操作?好的,它似乎与您建议的Romasz一起工作。我不知道怎么做,但我怀疑当我尝试构建操作/源URI的所有不同组合时,我一定是在尝试该技术时将构建操作设置为页面以外的其他内容。在您给出的示例中,让我们假设您希望UserControlLibs成为一个金块包。在这种情况下,如何合并资源字典?我发现选中“生成库布局”(Properties | Build中的一个选项)实际上会将文件放置到正确的位置。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///UserControlLibs/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///NAMESPACE_HERE/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
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 ***