在 C# 代码中构建 Silverlight DataTemplate

发布于 2024-09-24 18:17:11 字数 504 浏览 1 评论 0原文

这可能会引起更多的抗议,但在 Silverlight 代码中构建 DataTemplates 似乎是不可能的。我知道使用 XamlReader.Load(string) 的一个选项,使用这种方法会遇到几个问题:

  1. 没有验证,一切都是在连接的字符串中完成的。我们都知道这很糟糕

  2. 必须包含任何必要的资源,因为这将在其自己的上下文中运行。这也很糟糕,尽管有一个合乎逻辑的解释而不是一个阻碍。

  3. 任何在 DataTemplate 中包含事件调用的尝试都将失败,并出现 InvalidOperationException:控件的 XAML 无效:XamlReader.Load() 不接受事件处理程序。

No.3 对我来说似乎是一个令人惊叹的作品。如果有人提供一些线索、指示或想法来实现另一种/更好的方法,我将不胜感激。

在WPF中,有一个FrameworkElementFactory可以提供帮助,但是在Silverlight中似乎没有补救措施。

This might be more of an outcry, but building DataTemplates in Silverlight code seems to be impossible. The one option I am aware of being using XamlReader.Load(string), one is met with several issues using this approach:

  1. No validation, everything is done in concatenated strings. We all know this sucks

  2. Any necessary resources have to be included, as this will run in its own context. This also sucks, although there is a logical explanation and not a show-stopper.

  3. Any attempts to include event calls inside your DataTemplate will fail with InvalidOperationException: Invalid XAML for control: XamlReader.Load() does not accept event handlers.

No.3 seems to be a show-stopper for me. I would appreciate it if anyone gave some clues, pointers or ideas towards another / better way of doing this.

In WPF there is a FrameworkElementFactory that can provide assistance, however there seems to be no remedy for this in Silverlight.

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

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

发布评论

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

评论(1

嘿哥们儿 2024-10-01 18:17:11

也许您不需要在代码中构建数据模板。你真的需要这样做吗?

(#2) 您不需要包含 xaml 资源。它可以远程驻留在某个地方。您所要做的就是远程加载它。但也许我不明白你说的话。

Maybe you dont need to build datatemplates in code. Do you really need to do that?

(#2) You dont need to include the xaml resource. it could reside remotely somewhere. all you have to do is load it remotely. But maybe im not understanding what you said.

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