簡體   English   中英

ListBox在另一個ListBox中顯示選定的項目(圖像)(多重選擇模式)

[英]ListBox display selected Items (Image) in another ListBox (Selection Mode Multiple)

我只是嘗試在SelectionChanged事件中嘗試一些ListBox功能。

我有以下控件:

1.ListBox:名稱= ListBoxSource(我剛剛在XAML中添加了Image

2.ListBox:名稱= ListBoxDisplay

我只想迭代並從ListBoxSource選擇那些項目,並將其顯示到ListBoxDisplay 如何在循環中做到這一點?

ListBoxSource上的項目只是Image控件,而沒有其他控件。

我在網上找不到任何解決方案,因為大多數示例/解決方案都使用TextBlockTextBoxCheckBox ...並且沒有Images

foreach (Object selectedItem in ListBox1.SelectedItems)
{
    // What to do in here to add the selected Images to "ListBoxDisplay"
}

用這個

 <ListBox x:Name="ListBoxDisplay"
          ItemsSource="{Binding ElementName=ListBoxSource, Path=SelectedItems}"/>

而不是所有這些代碼。

另外:使用DataTemplate和DataBinding填充列表框,這將使此構造更加健壯和靈活。

for(int i=0;i<ListBoxSource.Items.Count;i++)
{
   Image currentImageItem = ListBoxSource.Items[i] as Image;
        Image image = new Image();
        image.Source = currentImageItem.Source ; 
   ListBoxDisplay.Items.Add(image);
}

對不起,我的錯誤是此代碼應該起作用,您必須處理其他屬性,例如width和height

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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