Silverlight 模板选择器解决方案效果很好,但不能混合
在开始之前,先介绍一下我如何使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您采用以下实现方式: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.