Silverlight 模板选择器解决方案效果很好,但不能混合

发布于 2024-09-18 09:58:17 字数 504 浏览 2 评论 0原文

在开始之前,先介绍一下我如何使用 Silverlight 实现模板选择器。

http://geekswithblogs.net/tkokke/archive/ 2009/09/28/datatemplateselector-in-silverlight.aspx

一切都很好。但该解决方案在混合中不起作用,使得整体上更难以可视化。正确的工作流程是从内容创建 UserControl 并将其嵌入到资源字典中以使其可混合,还是有更好的方法来做到这一点?

无论哪种方式,我都会问这个问题并同时发布模板选择器解决方案,因为我发现它很有用。非常欢迎更好的解决方案。

仅供参考.. sl4、.net4、最新混合.. 所有新玩具.. 使用 mvvm light(相关性不大)。

Before I begin here is a reference to how I implemented a template selector with Silverlight.

http://geekswithblogs.net/tkokke/archive/2009/09/28/datatemplateselector-in-silverlight.aspx

Everything works great. But the solution just doesn't work in blends making things more difficult to visualize overall. Is the correct work flow to just create a UserControl from the contents and embed it inside the Resource Dictionary to make it blendable, or is there a better way to do this?

Either way, I'm asking this question and posting the Template Selector solution at the same time, because I found it useful. Better solutions are very much welcome.

fyi.. sl4,.net4, latest blends.. all the new toys.. using mvvm light(little relevance).

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

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

发布评论

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

评论(1

樱娆 2024-09-25 09:58:17

我建议您采用以下实现方式:CodeProject 上的 DataTemplateSelector

您发布的链接的缺点是模板的位置和名称在 ContentControl 的实现中被硬编码。通过我链接到的文章中提供的方法,数据模板可以内联访问,或者通过常规的 {StaticResource} 引用(这意味着更大的灵活性)进行访问,最重要的是,Blend 知道如何处理它。

I would recommend you go with the the following kind of implementation: DataTemplateSelector on CodeProject.

The drawback of the link you posted is that the location and name of the templates are hard-coded in the ContentControl's implementation. With the approach provided in the article I link to, the data templates are accessed in-line, or by regular {StaticResource} references (which means more flexibility), and on top of that, Blend knows what to do with that.

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