Silverligth,如何将UserControl的可观测集合作为项源提供给列表框

本文关键字:列表 集合 UserControl 可观 Silverligth | 更新日期: 2023-09-27 18:21:04

我在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>

谢谢。

Silverligth,如何将UserControl的可观测集合作为项源提供给列表框

假设您有一个名为myUserControl1的UserControl,而myUserControl1.Menus是一个ObservableCollection

并且您希望将myListBox1.ItemsSource绑定到myUserControl1.Menus。然后您应该在绑定中使用ElementName关键字。例如:

<my:CustomControl x:Name="myUserControl1" />
<ListBox x:Name="myListBox1" 
         ItemsSource="{Binding Menus,ElementName=myUserControl1}" />