Saturday, October 8, 2011

Metro style apps–loading an image from content

 

I’m writing a Win8 Metro style app and I wanted to expose an image from one of my view models. The image comes from a file that I have included in the project as content. After wandering through the samples, I was finally able to piece together this solution:

image

The XAML binds to the property using the Source attribute:

image

Some things to note. The image’s Build Action is set to Content and the path delimiters in the call to ResourceLoader.GetFile() use forward slashes (“/”). Using a backslash results the exception: NamedResource Not Found (HRESULT 0x80073B17).