将图像应用于xaml中的列表框中的数据集合 [英] applying images to a collection of data in listbox in xaml

查看:89
本文介绍了将图像应用于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的常规WPF System.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 WPF System.Windows.Controls.ListBox which is based on System.Windows.Controls.ItemsControl and has the property Items used to add any UIElement objects. Add any object you need, for example, some panel with two children: a TextBlock with name and some kind of image of the type derived from System.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆