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.
Source="pack://siteoforigin:,,,/image.jpg" And its such an obvious syntax, how could I have missed it. :-) Gory details here: http://msdn2.microsoft.com/en-us/library/aa970069.aspx Michael 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 > clr.AddReference("PresentationFramework") > clr.AddReference("PresentationCore") > > 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() > app.Run(hello) > > > The XAML is: > > <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> > > <Grid> > <Image Source="images/image.jpg" Stretch="None" > HorizontalAlignment="Center" VerticalAlignment="Center"/> > </Grid> > > </Window> > > 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.BeginInit() > bi.UriSource = Uri("/images/image.jpg", UriKind.RelativeOrAbsolute); > bi.EndInit() > image.Source = bi > > Same problem - the image doesn't show. Anyone got any clues? > > Michael Foord > http://www.voidspace.org.uk/python/weblog/index.shtml > _______________________________________________ > Users mailing list > [email protected] > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
