[英]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.