سؤال

Trying to handle multi-resolution images in a Windows Phone Universal App I came across this article from Microsoft.

Unfortunately it only applies to Windows Phone 8 and Windows Phone Silverlight 8.1. When using the code samples they mention of:

private static bool IsWvga
{
    get
    {
        return App.Current.Host.Content.ScaleFactor == 100;
    }
}

In this case App.Current doesn't have a Host property - Host presumably being the SilverlightHost property mentioned here.

Has anyone found a way to do the equivalent in an 8.1 Universal App?

هل كانت مفيدة؟

المحلول

If you want to handle image scaling then it is handled by folder name in Windows Phone 8.1 Universal Apps. Here is how:

Image scaling in windows phone 8.1

To use these images in XAML you just give the file name and the OS does the rest.

 <Image Grid.Row="1" Grid.Column="0" Source="wpimages/resolution.jpg" VerticalAlignment="Top" Width="100"/>

An additional method is simply to have multiple copies of the image at different scales and to name them in the same way as the folders i.e resolution.scale-100.jpg, resolution.scale-240.jpg. You still name the file the same in your XAML.

I will share an article on that in the future.

نصائح أخرى

Quick update about Universal Windows Apps (UWP, Apps for Windows 10).

Microsoft extended the automatic scaling support in UWP and now supports more different scales (probably the most complete list is here - around 16 different, from 100% to 500%).

According to the article Porting Windows Runtime 8.x XAML and UI to UWP you just need to use 100/200/400:

Providing assets at 100%-scale, 200%-scale, and 400%-scale (in that priority order) will give you excellent results in most cases at all the intermediate scale factors.

Additionally, UWP supports different qualifiers (languages, scales, etc). Please read How to name resources using qualifiers (XAML)

On the personal side, I prefer to keep images in one folder, just to make life easier. It is easy to check if you have all the resolutions, it is easy to manage images (copy/delete/etc). Folders is way to go for Android, filenames - for iOS, Windows 10 supports both ways and it's great!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top