我正在尝试拆分一个包含多个控件样式的
在
这将始终产生以下异常:
我尝试过的一些URI格式如下:
ResourceDictionary
,该字典文件已经达到了大约3000行,变得难以管理。因此我决定将其拆分成更小、更具体的ResourceDictionaries
并使用 MergedDictionaries
进行合并。在
App.xaml
中实现此操作。<common:BootStrapper x:Class="Asteria.Ion.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="using:Template10.Common"
xmlns:styles="using:Asteria.Ion.Styles"
RequestedTheme="Dark">
<common:BootStrapper.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles\Custom.xaml" />
<ResourceDictionary Source="Styles\CustomControls.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</common:BootStrapper.Resources>
</common:BootStrapper>
CustomControls.xaml
包含对其他 ResourceDictionaries
的引用。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Template10.Controls"
xmlns:behaviors="using:Template10.Behaviors"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:local="using:Asteria.Ion.Styles">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Shared.xaml" />
<ResourceDictionary Source="Templates.xaml" />
<ResourceDictionary Source="ComponentBlock.xaml" />
<ResourceDictionary Source="FlowAgent.xaml" />
<ResourceDictionary Source="Planning.xaml" />
<ResourceDictionary Source="ProjectDialog.xaml" />
<ResourceDictionary Source="Inspector.xaml" /-->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
这将始终产生以下异常:
无法将类型“Windows.Foundation.String”分配给类型“Windows.Foundation.Uri”,因此无法将其分配给属性“Windows.UI.Xaml.ResourceDictionary.Source”。[行:12 位置:37]
我已经尝试过多次更改源URI,但它仍然会出现此错误。只有注释掉CustomControls.xaml中的所有ResourceDictionary元素才能帮助解决问题。但这样做会导致缺少样式的异常。我尝试过的一些URI格式如下:
/Styles/Shared.xaml
Styles/Shared.xaml
Styles\Shared.xaml
.\Shared.xaml
ms-appx:///Styles/Shared.xaml