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 ...

Get XAML Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.