I have a ListView-derived class which creates a bunch of user controls that are Panel-derived classes that contain a few controls each, most importantly a Image control (m_labelIcon). I am setting the image source for this control dynamically to one of the PNGs in my resource:
Uri uri = new Uri("/MyApp;component/Common/Main/res/drawable/some_icon.png");
StreamResourceInfo resourceInfo = Application.GetResourceStream(uri);
BitmapImage bitmapSource = new BitmapImage();
bitmapSource.CreateOptions = BitmapCreateOptions.None;
bitmapSource.SetSource(resourceInfo.Stream);
m_labelIcon.Source = bitmapSource;
However, when the list view appears, the images are all missing. If I scroll the list to the very bottom and then back to the top, the images start appearing. I’ve specified BitmapCreateOptions.None, which should prevent delay-loading the images (they are in my resource and not on the web).
I’ve also tried using the ImageOpened event, but this doesn’t work.
Any thoughts?
Thanks,
swine
After hours of the debugging, I stumbled upon the simple solution. Even though I was overriding ArrangeOverride() and MeasureOverride() like so:
I still needed to set the Width and the Height properties of the Image control manually in the constructor of my custom control like so:
THIS FIXED THE PROBLEM: