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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.