加入xClassNotDerivedFromElement错误时,code身后资源词典在Silverlight [英] xClassNotDerivedFromElement error when adding Code Behind to Resource Dictionary in silverlight

查看:145
本文介绍了加入xClassNotDerivedFromElement错误时,code身后资源词典在Silverlight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加code后面类资源词典中<一个描述href="http://stackoverflow.com/questions/92100/is-it-possible-to-set-$c$c-behind-a-resource-dictionary-in-wpf-for-event-handling">this问题。 (我知道这是不是一个好的做法,但它应该工作的基础上进行链接的问题的意见).I'm引用code与X:类属性:

I need to add code behind class to Resource Dictionary as described in this question. (I know that this is not a good practise but it should work based on the comments for linked question) .I'm referencing the code with x:Class attribute:

XAML(单独的资源词典文件):

XAML (separate Resource Dictionary file):

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="MyNamespace.MyStandardResources">
    ...
</ResourceDictionary>

code:

CODE:

using System.Windows;

namespace MyNamespace
{
    public partial class MyStandardResources : ResourceDictionary
    {
        public MyStandardResources()
        {
            InitializeComponent();
        }

        //...
    }
}

这会导致运行解析器异常:

This causes the runtime parser exception:

分析器内部错误:对象作家的 xClassNotDerivedFromElement 。 [行:XXX位置:XXX]。在System.Windows.Application.LoadComponent

Parser internal error: Object writer 'xClassNotDerivedFromElement'. [Line: xxx Position: xxx] at System.Windows.Application.LoadComponent.

这些资源包括在App.xaml中与ResourceDictionary.MergedDictionaries标签。

The resources are included in App.xaml with ResourceDictionary.MergedDictionaries tag.

推荐答案

你是不是想用这个作为ResourceDictionary中合并词典的来源值?如果是的话,不支持。你得到的xClassNotDerivedFromElement错误,这是一种不可思议的方式表明它的,但这里的原因:源属性值被转换在引用XAML的XAML,而不是作为一个类的方法。在XAML分析器将打开XAML因为没有任何precompile受益纯荷载作用,并不能调和的X:当时班

Are you trying to use this ResourceDictionary as a Source value of a merged dictionary? If so, that is not supported. You get that xClassNotDerivedFromElement error, which is a weird way of indicating it, but here's why: the Source attribute value gets translated in a way that references the XAML as XAML, not as a class. The XAML parser opens that XAML as a pure load action without benefit of any precompile, and can't reconcile the x:Class at that time.

这篇关于加入xClassNotDerivedFromElement错误时,code身后资源词典在Silverlight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆