我正在尝试从依赖类库项目中合并字典,但找不到资源键。注意:我正在使用Microsoft 的这个 Connect 错误解决方法,它应该允许框架搜索足够深以找到嵌套资源。这似乎不起作用。
失败示例
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/ResourceLibrary.xaml" />
<ResourceDictionary>
<Style TargetType="{x:Type Line}" /> <!-- workaround from MS to allow for this -->
<Main:AppBootstrapper x:Key="bootstrapper" /> <!-- CaliburnMicro bootstrapper, unsure if this is relevant -->
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
ResourceLibrary.xaml 内部
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="DefaultColorTheme.xaml" />
<!-- ...snip... -->
<ResourceDictionary Source="TransitionControl.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
执行此操作时,它找不到资源键。如果我从该类库中手动合并每个字典,它就可以正常工作。IMO,这开始破坏将资源抽象到外部程序集的目的。
成功范例
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/DefaultColorTheme.xaml" />
<ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/Images.xaml" />
<ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/FontIcons.xaml" />
<ResourceDictionary>
<Style TargetType="{x:Type Line}" />
<Main:AppBootstrapper x:Key="bootstrapper" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我是否将虚拟隐式样式放置在错误的位置?这里没有加起来。感谢您的关注。