之前看了下网上,分辨率都是用webview js拿或者全屏拿宽高,很有局限性。
研究一下。找到个完美的方法:
public Size GetDeviceResolution()
{
Size resolution = Size.Empty;
var rawPixelsPerViewPixel = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
foreach (var item in PointerDevice.GetPointerDevices())
{
resolution.Width = item.ScreenRect.Width * rawPixelsPerViewPixel;
resolution.Height = item.ScreenRect.Height * rawPixelsPerViewPixel;
break;
}
return resolution;
}
完美规避各种不方便,当然如果你想拿的是屏幕的实际大小,那就不要乘以
RawPixelsPerViewPixel就可以了