Sunday, August 26, 2012

Silverlight: how to display multiple properties of an object in a ListBox using DisplayMemberPath

Silverlight: how to display multiple properties of an object in a ListBox using DisplayMemberPath

I need to do this in code, not XAML.

Answers & Comments...

Answer: 1

With a ListBox, you can specify a DataItemTemplate - just put whatever controls you want in that DataItemTemplate (e.g. you might want multiple TextBlocks), and bind them to whatever properties you want on the bound object.

To load the DataItemTemplate dynamically, you can use the same technique as illustrated in this blog post.

by : slugsterhttp://stackoverflow.com/users/109702

Answer: 2

Its not possible to programmatically create the content of a data template in the same way you might create Controls and add them to a UserControl.

Instead you will need to use System.Xml.Linq.XDocument to construct the DataTemplate as XML with DataTemplate being the root element. Once complete you can retrieve the XML string for the Root element and then use XamlReader.Load to get a constructed DataTemplate.

by : AnthonyWJoneshttp://stackoverflow.com/users/17516




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog