[IronPython] [python] Loading Images from XAML with XamlReader (WPF)

John Messerly jomes at microsoft.com
Thu Dec 13 21:39:13 CET 2007


Michael Foord wrote:

> 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

Another workaround would be to use HtmlPage.DocumentUri & cook up an absolute Uri using that, but it looks like you found a good workaround already.

Relative URIs are actually a pretty tricky problem; one we're actively working on fixing. The current thinking is to have something like "MakeUri" or "GetRelativeUri" which takes a relative URI string, and returns an absolute System.Uri object which is relative to the executing Python file (which is how the relative URI should work). And of course, there will be a way to get the currently executing file path, if you want to cook up the Uri object yourself.

- John




More information about the Ironpython-users mailing list