Compact 7 Silverlight - 是否可以将DataBinding与混合数据类型一起使用? [英] Compact 7 Silverlight - Is it possible to use DataBinding with Mixed Data Types?

查看:133
本文介绍了Compact 7 Silverlight - 是否可以将DataBinding与混合数据类型一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示一个列表框,其中每个项目可以是两种或三种不同的类型。例如,当数据项包含布尔值时,一个ListboxItem可能具有CheckBox,如果数据类型需要多个选项,则另一个具有ComboBox,而另一个
可能具有需要字符串值的TextInput字段。  


对于上述内容,我需要在DataTemplate中使用三种不同的控件:

< DataTemplate x:键= QUOT; BooleanTemplate"> 
< local:BooleanItemControl />
< / DataTemplate>
< DataTemplate x:Key =" IntTemplate">
< local:IntItemControl />
< / DataTemplate>
< DataTemplate x:Key =" StringTemplate">
< local:StringItemControl />
< / DataTemplate>


有没有办法将数据绑定到Listbox,以便它知道要使用哪个DataTemplates?


CLight

解决方案

不要在ListBox本身上设置DataTemplate。


动态设置ListBoxItem上的DataTemplate。根据您获得的数据类型。


在该ListboxItem上设置数据上下文。将listboxitem添加到itemcollection(列表框)。



浏览 链接:http://social.msdn.microsoft.com/Forums/en/wpf/thread/b32c6a22-48e0-4f5b -9505-2ba98a9af5e5


使用C ++在Silverlight for Windows Embedded中执行类似的实现。



要动态设置模板,请使用IXRControlSetTemplate ...
http://msdn.microsoft.com /en-us/library/ee501580.aspx


I need to display a listbox where each item could be of two or three different types. For example one ListboxItem might have a CheckBox when the data item contains a boolean value, another has a ComboBox if the data type requires multiple options and another might have a TextInput field where a string value is required.  

For the above I would need three different Controls to be used in a DataTemplate:

<DataTemplate x:Key="BooleanTemplate">
	<local:BooleanItemControl />
</DataTemplate>
	<DataTemplate x:Key="IntTemplate">
<local:IntItemControl />
	</DataTemplate>
<DataTemplate x:Key="StringTemplate">
	<local:StringItemControl />
</DataTemplate>

Is there a way to bind the data to a Listbox so that it knows which of the DataTemplates to use?


CLight

解决方案

Dont set DataTemplate on ListBox itself.

Set DataTemplate on ListBoxItem dynamically. Based on the type of data you get.

Set Data context on that ListboxItem. Add the listboxitem to itemcollection (of the listbox).

Go through the link:http://social.msdn.microsoft.com/Forums/en/wpf/thread/b32c6a22-48e0-4f5b-9505-2ba98a9af5e5

Do similar implementation in Silverlight for Windows Embedded using C++.

To set template dynamically use IXRControlSetTemplate... http://msdn.microsoft.com/en-us/library/ee501580.aspx


这篇关于Compact 7 Silverlight - 是否可以将DataBinding与混合数据类型一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆