简体   繁体   中英

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://dotnet-redzone.blogspot.com/2010/05/datatemplate-selector-with-silverlight.html

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

I'm developing for 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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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