简体   繁体   中英

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

But I dont know where to put may own object with images, etc. Or add new object on this VirtualizedDataSource.

EDIT: What Im trying to say here is, is there a sample usage of this VirtualizedDataSource for a custom object? Custom object with image,text,etc... Because in the sample, the data is only a string..

The way you put images as items into a ListBox is the same, regardless of whether you are using virtualization or not. 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.

<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. 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

If you use the Control Toolbox's LongListSelector, then you can handle the Link and Unlink events to do the same kind of thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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