문제

I am building up a string for the source attribute of some of my images in a Windows 8.1 store app.

I need to detect the scale factor that the device requires so that I can append the correct .scale-n to the end of the string. These image sources are external to the app so I cannot rely on Windows' automatic scaling by just referencing the image without the scale-n part.

So I need to know whether I should append scale-100, scale-140 or scale-180 to the image URL.

How can I work this out in c# and xaml?

도움이 되었습니까?

해결책 2

I found a solution for this:

I created this variable:

ResolutionScale resolutionScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ResolutionScale;

and then I used a switch statement:

switch (resolutionScale)
{
  case ResolutionScale.Scale100Percent:
    //Device is 100
    break;
  case ResolutionScale.Scale140Percent:
    //Device is 140
    break;
  case ResolutionScale.Scale180Percent:
    //Device is 180
    break;
}

다른 팁

ResolutionScale resolutionScale = DisplayInformation.GetForCurrentView().ResolutionScale;
double factor = (double)resolutionScale / 100.0;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top