c# - Populate ItemsControl from a Collection which is incomplete -


i need create pdf previewer in wpf , want display pages in itemscontrol bound observablecollection of rendered pages (each page bitmapsource instance). itemscontrol inside scrollviewer. now, don't want render pages @ once because there can hundred of them , eat memory fast. want render ones visible in app window. but, @ same time want itemscontrol big number of pages in pdf document scrollviewer's scrollbar adequately small , shows how more there scroll.

so question is, how make itemscontrol big number of pages not make observablecollection have pages?

i considered replacing itemscontrol grid , add dummy items height set height of page , replace actual page when it's visible user seems lot of work.

instead of having observablecollection<bitmapsource> (which seemingly have) should have observablecollection<page>, page class bitmapsource property implements inotifypropertychanged interface, e.g.

public class page : inotifypropertychanged {     public event propertychangedeventhandler propertychanged;      private bitmapsource image;      public bitmapsource image     {         { return image; }         set         {             image = value;             propertychanged?.invoke(this,                 new propertychangedeventargs(nameof(image)));         }     } } 

you create many page instances there pages in document , put them observablecollection. when page loaded, assign image property, trigger binding in itemtemplate:

<itemssource.itemtemplate>     <datatemplate>         <image source="{binding image}"/>     <datatemplate> </itemssource.itemtemplate> 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -