[英]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
控件,而没有其他控件。
我在网上找不到任何解决方案,因为大多数示例/解决方案都使用TextBlock
, TextBox
或CheckBox
...并且没有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.