Quickstart: Using file or image resources (XAML)
You can add images and other file resources to your app, and reference those files from within your app. Support for swapping images based on high contrast settings or display scaling is built in, if you follow the instructions below for naming and organizing your file resources in folders.
Instructions
Create tailored images or other file assets for different scales (dpi) and contrast settings.
Create your images at several recommended sizes, to ensure that your app looks great when Windows scales it. See the guidelines for scaling to pixel density.
Create multiple copies of each image:
- Original size, for a typical 96dpi device.
- 140% the original size. For example, a 100x100px image should also have a 140x140px image version.
- 180% the original size. For example, a 100x100px image should also have a 180x180px image version.
- 240% the original size, for Windows Phone apps. For example, a 100x100px image should also have a 240x240px image version.
- For the logo, wideLogo, and smallLogo resources specified in the app's manifest file, 80% of the original size. For example, a 100x100px image should also have an 80x80px image version. See App images and Tile image sizes.
- High contrast image with a black background and white foreground at the original size.
- High contrast image with a white background and black foreground at the original size.
Name the images with qualifiers for the various scales and contrast settings:
- name.scale-100.ext
- name.scale-140.ext
- name.scale-180.ext
- name.scale-240.ext
- name.scale-80.ext (For the logo, wideLogo, and smallLogo resources)
- name.scale-100_contrast-black.ext
- name.scale-100_contrast-white.ext
In this example, name.ext is the name of the image as referenced in code and markup.
Place the images side by side in the same folder. For example:
- images/logo.scale-100.png
- images/logo.scale-140.png
- images/logo.scale-180.png
- images/logo.scale-240.png
- images/logo.scale-80.png
- images/logo.scale-100_contrast-black.png
- images/logo.scale-100_contrast-white.png
Refer to the images in XAML without the qualifiers.
<Image Source="images/logo.png" />
Refer to the images in code without the qualifiers.
var uri = new System.Uri("ms-appx:///images/logo.png"); var file = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
Refer to the image in the manifest without the qualifiers.
Open the Package.appxmanifest file in Microsoft Visual Studio.
Edit the manifest reference to refer to the file in the correct element or attribute, such as:
Logo: images\logo.png
Some images or other files may need to be localized, particularly when they contain text or culturally sensitive material. Files can also vary depending on a user's location, separate from their language. For example, a map may have different borders depending on the user's location, but the labels should follow the user's preferred language.
Files can be marked or qualified with basic folder and file name conventions for all different user and device configurations. See How to name resources using qualifiers for more details on qualifying resources, and for a list of qualifiers.
Related topics
How to name resources using qualifiers