简体   繁体   English

在Silverlight中为wp7选择动态数据模板吗?

[英]Dynamic Data Template Selecting in Silverlight for wp7?

I have a list of different types of elements. 我列出了不同类型的元素。 I would like to display a different data template for different list elements, based on what type it is. 我想根据不同的列表类型显示不同的数据模板。 I have found a bunch of examples of how to do this online, but they look ridiculously complex and error prone. 我已经找到了很多在线操作示例,但它们看起来异常复杂且容易出错。 Is there a more elegant way? 有没有更优雅的方式?

http://csharperimage.jeremylikness.com/2010/11/silverlight-data-template-selector.html http://csharperimage.jeremylikness.com/2010/11/silverlight-data-template-selector.html

http://dotnet-redzone.blogspot.com/2010/05/datatemplate-selector-with-silverlight.html http://dotnet-redzone.blogspot.com/2010/05/datatemplate-selector-with-silverlight.html

http://blog.geeky.cc/post/2009/09/11/Silverlight-DataTemplateSelector.aspx http://blog.geeky.cc/post/2009/09/11/Silverlight-DataTemplateSelector.aspx

I'm developing for Windows Phone 7. 我正在为Windows Phone 7开发。

Those examples for the most part appear to be just what you need. 这些示例在大多数情况下似乎正是您所需要的。 If you are looking for a more packaged approach there is one available on CodeProject . 如果您正在寻找一种更打包的方法,可以在CodeProject上找到一种方法。

One reason is may feel overly complex or perhaps requiring large amount of code for something that appears trivial is that Silverlight does not contain a DataTemplateSelector class as does WPF. 原因之一可能是看起来过于复杂,或者可能需要花费大量代码才能完成一些琐碎的事情,因为Silverlight不像WPF那样包含DataTemplateSelector类。

Either way the CodeProject offering or one of the offerings you posted (ignoring the one geared at MEF unless you are making use of MEF) should suffice in giving you what you need. 无论哪种方式, CodeProject产品或您发布的产品之一(除非您使用MEF都忽略适用于MEF的产品)都足以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM