O'Reilly logo

XAML Unleashed by Adam Nathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Referencing Files with URIs

The mapping of an Image element in XAML to the equivalent C# code is not always obvious. The preceding example:

<Image Source="Assets/Logo.png"/>

is equivalent to the following C# code placed in a Page’s code-behind in a Windows Store or universal app:

Image image = new Image();image.Source = new BitmapImage(new Uri(this.BaseUri, "Assets/Logo.png"));

There are two things going on here. One is that a type converter hides the complexity involving ImageSource, the type of the Source property. An ImageSource cannot be directly instantiated, nor can its BitmapSource subclass, but BitmapSource has two subclasses that can be instantiated: BitmapImage, the one typically ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required