将图像应用于xaml中的列表框中的数据集合 [英] applying images to a collection of data in listbox in xaml
问题描述
我正在通过一种方法填充列表框(基本上它会在目录中显示文件夹列表),我浏览了一些博客,内容涉及将图像手动或单独绑定到列表框,但是我将图像绑定到列表框想要将Image动态绑定到集合的每个条目(列表框的数量每次都会更改).看起来应该像下面这样(最重要的是,所有内容都应该在XAML中).
[image]列表条目1
[image]清单enrty 2
......
我在某种程度上研究过xaml,如下所示.
Hi,
I''m working on populating A list-box through a method( basically it brings the list of folders in a directory), I have gone through several blogs about binding images to the list-box manually or individually to single entry, but I want to bind an Image to each entry of the collection dynamically ( the quantity of the list-box changes every time). It should look something like this below (Most Importantly everything should be in XAML).
[image] list entry 1
[image] list enrty 2
......
I have worked on the xaml to some extent, it looks as follows.
<UserControl.Resources>
<DataTemplate x:Key="listBoxTemplate">
<StackPanel Margin="3" Orientation="Horizontal">
<ListBox>
<TextBlock Text="Name:" />
<TextBlock Text="{Binding CustomerFolders}" />
</ListBox>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
.
.
.
<ListBox Name="listBox1" Margin="10" SelectionMode="Single" ItemsSource="{Binding CustomerFolders}" DataContext="listBoxTemplate" >
</ListBox>
请建议我或通过任何可能有用的示例或博客指导我.
谢谢
Pete.
Kindly suggest me or guide me trough any samples or blogs which might be helpful.
Thanks
Pete.
推荐答案
您可以使用基于System.Windows.Controls.ItemsControl
且具有用于添加任何UIElement
对象的属性Items
的常规WPFSystem.Windows.Controls.ListBox
. .添加您需要的任何对象,例如,带有两个子对象的面板:具有名称的TextBlock
和源自System.Windows.Media.ImageSource
的某种类型的图像.
这几乎就是您所需要的.
参见:
http://msdn.microsoft.com/en-us/library/system. windows.controls.itemscontrol.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.controls.listbox.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx#inheritanceContinued [ ^ ],
http://msdn.microsoft.com/zh-cn/library/system.windows.controls.textblock%28v = VS.100%29.aspx [ http://msdn.microsoft.com/en-us/library/system. windows.media.imagesource.aspx [ ^ ].
—SA
You can use a regular WPFSystem.Windows.Controls.ListBox
which is based onSystem.Windows.Controls.ItemsControl
and has the propertyItems
used to add anyUIElement
objects. Add any object you need, for example, some panel with two children: aTextBlock
with name and some kind of image of the type derived fromSystem.Windows.Media.ImageSource
.
That''s pretty much all you need.
See:
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx#inheritanceContinued[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock%28v=VS.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imagesource.aspx[^].
—SA
这篇关于将图像应用于xaml中的列表框中的数据集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!