[英]Silverligth, how to give an observablecollection of UserControl as itemsource to a listbox
I have a list of observable collection of UserControl in my MVVM silverlight project. 我的MVVM silverlight项目中有一个可观察到的UserControl集合。 I want to give them as source to a listbox datasource. 我想将它们作为列表框数据源的源。 How can I achieve this. 我该如何实现。
<ListBox VerticalAlignment="Stretch" Style="{StaticResource Menu}" ItemsSource="{Binding Menus}" DisplayMemberPath="Libelle" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<ItemsControl ItemsSource="{Binding Menus.UnderControl}" /> </ListBox>
Thanks. 谢谢。
Let us say you have a UserControl called myUserControl1
, and myUserControl1.Menus
is an ObservableCollection
. 假设您有一个名为myUserControl1
的UserControl,而myUserControl1.Menus
是一个ObservableCollection
。
and you wish to bind myListBox1.ItemsSource to myUserControl1.Menus. 并且您希望将myListBox1.ItemsSource绑定到myUserControl1.Menus。 Then you should use the ElementName key word in your binding. 然后,应在绑定中使用ElementName关键字。 For example: 例如:
<my:CustomControl x:Name="myUserControl1" />
<ListBox x:Name="myListBox1"
ItemsSource="{Binding Menus,ElementName=myUserControl1}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.