XAML editor complains “Object does not match target type” for SharedResourceDictionary.Source

北慕城南 提交于 2020-01-14 09:39:06

问题


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; }
    }
}

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?

Update: In fact, replacing the utils:SharedResourceDictionary with just the ResourceDictionary makes it work without error.

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>

and Visual Studio Design editor just complains exactly the same. And it works if I just replace utils:SharedResourceDictionary with ResourceDictionary.

Update3: SharedResourceDictionary is minimalistic now but XAML editor still complains.


回答1:


I was told (by a Microsoft employee) that the bug Dudu submitted (thanks!)

https://connect.microsoft.com/VisualStudio/feedback/details/1820572/xaml-designer-gives-error-object-does-not-match-target-type-for-derived-resourcedictionary-property

should be fixed on update: https://msdn.microsoft.com/en-us/library/61f460b4-d173-45b8-8347-003e863ef074




回答2:


It might be very well an issue of VS2015; I've had issues with the XAML editor of it myself, giving errors for XAML files I've written in VS2013 and were tested and working. Try opening the project in VS2013, it might solve the issue. No promises on this one.



来源:https://stackoverflow.com/questions/31726759/xaml-editor-complains-object-does-not-match-target-type-for-sharedresourcedict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!