Just to clarify - creating an image directly from code *does* work. But 
I still want (need?) to know why it doesn't work when loaded from XAML?

This is the working code:

import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")

from System import Uri, UriKind
from System.Windows.Markup import XamlReader

from System.Windows import (
   Application, Window
)

from System.Windows.Controls import Image
from System.Windows.Media.Imaging import BitmapImage


class HelloWorld(Window):
   def __init__(self):
      self.Width = 500
      self.Height = 500
      self.Title = 'Example'
      image = Image()
     
      bi = BitmapImage()
      bi.BeginInit()
      bi.UriSource = Uri("images/image.jpg", UriKind.RelativeOrAbsolute);
      bi.EndInit()
      image.Source = bi
      print image.ActualHeight, image.ActualWidth
      self.Content = image
     
     
hello = HelloWorld()

app = Application()
app.Run(hello)

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
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to