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