0

I have a ListBox using a Panel as its ItemsPanel

What I would like to do is load the bytes for an image into the bound property in the view model for each ListBoxItem that is currently on screen, and unload the bytes when they are scrolled off screen.

I have tried Panel.OnVisualChildrenChanged. This tells me when items are added or removed to the panel, but doesn't seem to help my specific case.

I have tried

<Style TargetType="{x:Type ListBoxItem}">
 <EventSetter Event="RequestBringIntoView" Handler="EventSetter_OnHandler" />
</Style>

That event never seems to fire. edit: fires when item is selected

I have also gotten a reference to the ListBox ScrollViewer to look at the VerticalOffset and Viewport.Height/Width but I don't see how that information helps me.

Julien
  • 212
  • 1
  • 18
  • 53
  • This doesn't answer your question, but are you changing the template of the ListBox? As long as virtualization isn't disabled, this is how a listbox renders, by default. See: https://msdn.microsoft.com/library/cc716879%28v=vs.100%29.aspx – Khale_Kitha Feb 18 '16 at 18:35
  • I am defining my own ListBoxItem template – Julien Feb 18 '16 at 18:36
  • Gotcha :) I would advise providing some information on the changes you've made to the template, and you'll have better success at getting responses. Also, take a look, [here](http://stackoverflow.com/questions/28354139/how-to-use-ui-virtualization-with-redefined-listbox-templates) if you haven't already, in case it helps. – Khale_Kitha Feb 18 '16 at 18:40
  • What kind of information about the template is relevant? – Julien Feb 18 '16 at 18:48
  • Start with posting the actual ItemTemplate, and that may help. Someone may be able to suggest a change that will allow virtualization to be used without you having to design it, from scratch. – Khale_Kitha Feb 18 '16 at 18:56
  • Virtualization is being used. The issue is the listbox contains many items and one of the bound values is a byte array – Julien Feb 18 '16 at 19:19
  • 1
    Its been a while, but I used to use a helper method [here](http://stackoverflow.com/a/6765303/302677) of `IsObjectVisibleInContainer` to determine if an item is visible within it's parent container. That could probably point you in the right direction, if it doesn't give you your answer outright :) – Rachel Feb 18 '16 at 20:11

0 Answers0