XAML 编辑器抱怨“对象与目标类型不匹配"对于 SharedResourceDictionary.Source [英] XAML editor complains "Object does not match target type" for SharedResourceDictionary.Source
问题描述
我们在项目中使用 SharedResourceDictionary.该词典是根据 SO 上的几篇文章构建的.但我已将其简化为:
We use SharedResourceDictionary in our project. The dictionary is constructed from several posts here on SO. But I have reduced it to this:
public class SharedResourceDictionary : ResourceDictionary
{
public new Uri Source
{
get { return base.Source; }
set { base.Source = value; }
}
}
在新的 VS2015 中设计的 XAML 无法加载样式并报错
In new VS2015 the XAML designed cannot load the styles and complains
1. The resource "..." could not be resolved.
2. Object does not match target type.
3. The resource "..." could not be resolved.
4. The resource "..." could not be resolved.
5. The resource "..." could not be resolved.
在以下标记中(下划线文本是抱怨的地方):
in the following markup (underscored text is where it complains):
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="_1_{StaticResource ...}__"
...
>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<utils:SharedResourceDictionary _2_Source="pack://application:,,,/.../Styles.xaml"__ />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Style="_3_{StaticResource ...}__">
资源和控件位于不同的程序集中.
the resources and controls are in different assemblies.
您是否有过同样的经历或知道解决方案?
Have you maybe experience the same or do know the solution?
更新:实际上,将 utils:SharedResourceDictionary
替换为 ResourceDictionary
可以使其正常工作.
Update: In fact, replacing the utils:SharedResourceDictionary
with just the ResourceDictionary
makes it work without error.
Update2:这个问题不是因为 Styles.xaml
- 我创建的资源文件几乎是空的:
Update2: This issue is not because of Styles.xaml
- I've created almost empty resource file:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="Test" Color="#FFFFFF" />
</ResourceDictionary>
和 Visual Studio Design 编辑器抱怨的完全一样.如果我只是将 utils:SharedResourceDictionary
替换为 ResourceDictionary
,它会起作用.
and Visual Studio Design editor just complains exactly the same. And it works if I just replace utils:SharedResourceDictionary
with ResourceDictionary
.
Update3:SharedResourceDictionary 现在是简约的,但 XAML 编辑器仍然抱怨.
Update3: SharedResourceDictionary is minimalistic now but XAML editor still complains.
推荐答案
我(一位微软员工)告诉我 Dudu 提交的 bug(谢谢!)
I was told (by a Microsoft employee) that the bug Dudu submitted (thanks!)
应该在更新时修复:https://msdn.microsoft.com/en-us/library/61f460b4-d173-45b8-8347-003e863ef074
这篇关于XAML 编辑器抱怨“对象与目标类型不匹配"对于 SharedResourceDictionary.Source的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!