[IronPython] [python] Loading Images from XAML with XamlReader (WPF)
fuzzyman at voidspace.org.uk
Thu Dec 13 19:41:21 CET 2007
Sorry about the noise guys, but having found the solution I guess I
ought to share it. The answer is (wait for it...)... use site of origin
relative syntax for the Source tag.
And its such an obvious syntax, how could I have missed it. :-)
Gory details here:
Michael Foord wrote:
> Hello guys,
> I'm struggling to load images from XAML using the XamlReader with
> IronPython. The equivalent with compiled XAML and C# works fine -
> however this doesn't directly use the XamlReader so I wonder if it is an
> issue with that?
> The Python code is:
> import clr
> from System.IO import File
> from System.Windows.Markup import XamlReader
> from System.Windows import (
> Application, Window
> class HelloWorld(Window):
> def __init__(self):
> stream = File.OpenRead("HelloWorld.xaml")
> self.Content = XamlReader.Load(stream)
> hello = HelloWorld()
> app = Application()
> The XAML is:
> <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> <Image Source="images/image.jpg" Stretch="None"
> HorizontalAlignment="Center" VerticalAlignment="Center"/>
> The image stubbornly refuses to appear and reports an ActualHeight and
> ActualWidth of 0.0 if I inspect it.
> I've even tried instantiating a BitmapImage directly from code and
> setting it as the Source on the image:
> image = root.FindName("image")
> bi = BitmapImage()
> bi.UriSource = Uri("/images/image.jpg", UriKind.RelativeOrAbsolute);
> image.Source = bi
> Same problem - the image doesn't show. Anyone got any clues?
> Michael Foord
> Users mailing list
> Users at lists.ironpython.com
More information about the Ironpython-users