简体   繁体   English

如何在带有图像的列表框上使用数据虚拟化?

[英]How can I use Data Virtualization on listbox with image?

newbie here..新手来了。。

Here's the link for listbox data virtualization http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx?PageIndex=2#comments这是列表框数据虚拟化的链接http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx?PageIndex=2 #注释

But I dont know where to put may own object with images, etc. Or add new object on this VirtualizedDataSource.但我不知道在哪里放可能拥有带有图像的 object 等。或者在这个 VirtualizedDataSource 上添加新的 object。

EDIT: What Im trying to say here is, is there a sample usage of this VirtualizedDataSource for a custom object?编辑:我在这里想说的是,是否有此 VirtualizedDataSource 用于自定义 object 的示例用法? Custom object with image,text,etc... Because in the sample, the data is only a string..自定义 object 带有图像,文本等...因为在示例中,数据只是一个字符串..

The way you put images as items into a ListBox is the same, regardless of whether you are using virtualization or not.无论您是否使用虚拟化,将图像作为项目放入 ListBox 的方式都是相同的。 You bind the ItemsSource property of the listbox to a collection of objects, and then use a DataTemplate to define how to render each object, for example binding a XAML Image's Source to a BitmapImage property on your object.您将列表框的 ItemsSource 属性绑定到对象集合,然后使用 DataTemplate 定义如何呈现每个 object,例如将 XAML Image 的 Source 绑定到 ZA8CFDE6331BD49EB62AC96F8911 上的 BitmapImage 属性

<Image 
    Source="{Binding ABitmapImageProperty}"
    ...
/>

Virtualization comes into play in that you might not want to keep those BitmapImages in memory once the corresponding ListBox elements have scrolled off page.虚拟化开始发挥作用,因为一旦相应的 ListBox 元素滚出页面,您可能不想将这些 BitmapImages 保留在 memory 中。 You can do this in the standard ListBox by setting up a handler for the VirtualizingStackPanel.CleanUpVirtualizedItem event: http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.cleanupvirtualizeditemevent(v=VS.95).aspx您可以通过为 VirtualizingStackPanel.CleanUpVirtualizedItem 事件设置处理程序在标准 ListBox 中执行此操作: http://msdn.microsoft.com/en-us/library/system.windows.virtualizingstackPanel(VS.cleanup. 95).aspx

If you use the Control Toolbox's LongListSelector, then you can handle the Link and Unlink events to do the same kind of thing.如果您使用 Control Toolbox 的 LongListSelector,那么您可以处理 Link 和 Unlink 事件来做同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM