在 C# 代码中构建 Silverlight DataTemplate
这可能会引起更多的抗议,但在 Silverlight 代码中构建 DataTemplates 似乎是不可能的。我知道使用 XamlReader.Load(string) 的一个选项,使用这种方法会遇到几个问题:
没有验证,一切都是在连接的字符串中完成的。我们都知道这很糟糕
必须包含任何必要的资源,因为这将在其自己的上下文中运行。这也很糟糕,尽管有一个合乎逻辑的解释而不是一个阻碍。
任何在 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:
No validation, everything is done in concatenated strings. We all know this sucks
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您不需要在代码中构建数据模板。你真的需要这样做吗?
(#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.