使用代码在 Silverlight 中创建 HierarchicalDataTemplate

发布于 2024-08-10 13:22:20 字数 923 浏览 1 评论 0原文

我正在尝试按照有关从代码创建 DataTemplates 的建议,在 Silverlight 中的代码中创建一个 HierarchicalDataTemplate (来自 Silverlight Toolkit):

在代码中创建 Silverlight DataTemplate

但是,我无法让它适用于 HierarchicalDataTemplate< /代码>。

我尝试使用 Silverlight Toolkit 附带的 XamlBuilder,但这给了我一个错误。

我尝试过 XamlReader,并包含了各种默认和前缀命名空间,但没有成功。

如果我运行 XamlBuilder 的 Build 方法,我会得到以下字符串:

<HierarchicalDataTemplate xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:attached=\"clr-namespace:MyStuff;assembly=MyStuff\" xmlns=\"clr-namespace:System.Windows;assembly=System.Windows.Controls\"><attached:MyUserControl /></HierarchicalDataTemplate>

我得到的错误是:

AG_E_PARSER_NAMESPACE_NOT_SUPPORTED

I'm trying to create a HierarchicalDataTemplate (from the Silverlight Toolkit) in code in Silverlight following this advice on creating DataTemplates from code:

Creating a Silverlight DataTemplate in code

However, I haven't been able to get it to work for HierarchicalDataTemplate.

I tried using XamlBuilder that ships with Silverlight Toolkit, but that gives me an error.

I've tried XamlReader, and have included various default and prefixed namespaces, but with no luck.

If I run XamlBuilder's Build method, I get the following string:

<HierarchicalDataTemplate xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:attached=\"clr-namespace:MyStuff;assembly=MyStuff\" xmlns=\"clr-namespace:System.Windows;assembly=System.Windows.Controls\"><attached:MyUserControl /></HierarchicalDataTemplate>

The error I get is:

AG_E_PARSER_NAMESPACE_NOT_SUPPORTED

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

使用 Silverlight Xaml 解析器,默认 xmlns必须为“http ://schemas.microsoft.com/winfx/2006/xaml/presentation”,即使您不使用它。因此,将该 xmlns 声明添加到 Xaml 字符串中,并更改 System.Windows clr-namespace 声明以使用某些前缀。

With the Silverlight Xaml parser, the default xmlns must be "http://schemas.microsoft.com/winfx/2006/xaml/presentation", even if you don't use it. So add that xmlns declaration to your Xaml string, and change the System.Windows clr-namespace declaration to use some prefix.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文