簡體   English   中英

Silverligth,如何將可觀察的UserControl集合作為項目源提供給列表框

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM