gpt4 book ai didi

.net - 在 Silverlight 中将代码隐藏添加到资源字典时出现 xClassNotDerivedFromElement 错误

转载 作者:行者123 更新时间:2023-12-04 06:49:04 27 4
gpt4 key购买 nike

我需要将类背后的代码添加到资源字典中,如 this question 中所述. (我知道这不是一个好的做法,但它应该根据链接问题的评论工作)。我正在引用带有 x:Class 属性的代码:

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

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

代码:
using System.Windows;

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

//...
}
}

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

解析器内部错误:对象编写器“ ” xClassNotDerivedFromElement '。 [行:xxx 位置:xxx] 在 System.Windows.Application.LoadComponent。

资源包含在 App.xaml 中,带有 ResourceDictionary.MergedDictionaries 标记。

最佳答案

您是否尝试将此 ResourceDictionary 用作合并字典的 Source 值?如果是这样,则不支持。您会收到 xClassNotDerivedFromElement 错误,这是一种奇怪的指示方式,但原因如下:Source 属性值以将 XAML 引用为 XAML 而不是类的方式进行转换。 XAML 解析器将该 XAML 作为纯加载操作打开,没有任何预编译的好处,并且当时无法协调 x:Class。

关于.net - 在 Silverlight 中将代码隐藏添加到资源字典时出现 xClassNotDerivedFromElement 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3370661/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com