Hello,

I don't know if this is more an IronPython (2.6.1) issue than a Silverlight (4) issue, but I hope that I am talking to the right audience again (thank you for the great answers last time).

I've created an `Image` class managing images based on System.Windows.Media.Imaging.BitmapImage. My method `image_instance.load_and_show()` should load the image from a given URI and then show it in an XAML <image /> element. The important thing is that the showing part should only happen after it is sure that the image has loaded correctly. To control this, I use the BitmapImage.ImageOpened event. This is the relevant part of the code from my `Image` class:


    def load_and_show(self):
        self.bi = BitmapImage(Uri(self.abspath, UriKind.Absolute))
        self.bi.ImageOpened += self.successfully_loaded_now_show
        self.bi.ImageFailed += self.load_failed
        #self.xaml_main_image.Source = self.bi # LINE A

    def successfully_loaded_now_show(self, s, e):
        debug("image loaded: %s" % s.UriSource) # LINE B
        self.xaml_main_image.Source = self.bi # LINE C

    def load_failed(self, s, e):
        debug("image load failed") # LINE D


If the code is like shown above and I do `image_instance.show_and_load()`, nothing happens. More exactly, LINE B, C, and D are not reached. It is like *neither the event ImageOpened nor ImageFailed is toggled*.

If I re-activate (or un-outcomment =)) LINE A, the callbacks magically work properly, i.e. after calling `image_instance.show_and_load()` the image shows up in the UI (either via LINE A or C), and LINE B is definitely reached (or LINE D in case of a wrong URI).

The point is that I don't want LINE A, because showing the image should happen in a more controlled manner. What's the problem in my approach, why are the callbacks not called?

Thank you in advance,

Jan-Philip Gehrcke
--
http://gehrcke.de
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to