开发者

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

开发者 https://www.devze.com 2022-12-20 08:59 出处:网络
I开发者_Python百科 need to do this in code, not XAML.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.

I开发者_Python百科 need to do this in code, not XAML.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消