How to properly enable dpi-scaling on uwp app - xaml

I've created my first UWP app. It's a Windows 8.1 UWP app which will help with scheduling courses at my university who's current system is awful. I've been working on it with my Windows 10 desktop computer with a 1080p monitor at default system scaling (100%). I deployed a test build and installed it on my laptop. The laptop is also Windows 10 and 1080p but has a smaller screen so I have system scaling set to 125%. My problem is that instead of this higher scaling factor making my app have bigger features, it does the opposite and shrinks everything in the app.
Here are two screenshots from my laptop when running at different scaling factors. The first is at 100% where everything on the system is too small.
Note that the navigation bar on the left is exactly 44 pixels wide, as design. Now in the next screenshot the laptop is running at 125% system scaling (I logged out and in before taking the screenshot so scaling should have updated fully). We should expect that the nav bar be 55 pixels wide.
Here you can see that areas in the app actually got smaller than they were before. The nav bar here is about 37 pixels wide compared to the 55 I expected. Is there something I missed in how I must scale a UWP app?
I do not have the entire xaml code with me at the moment as I am on my laptop, but I know that nav bar is part of a grid which looks like this. This grid is the overall grid that is running the app, with the nav bar being the first column.
<Grid x:name="gridOverall">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="44"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
...
</Grid>
I thought it might have been an enable-scaling option in the app manifest or something but I couldn't find anything like it. I expected issues like this to arise with the images I used as I did not yet include higher resolution options yet, but I didn't expect this to happen with layout elements that are defined in the xaml.
Can anyone shed some insight on what might be going on? This is my first full app and I'm a little lost.

Windows 8.1 doesn't have a concept of 125% scaling; it uses 100% / 140% / 180%. The value of DisplayInformation.ResolutionScale will be 100. So it's actually scaled by 80% (100 / 125). And 44 * 0.8 is ~35.
Note: The following is not supported since it relies on reflection and using features of Windows 10 inside a Windows 8.1 app. Use at your own risk.
Here's one way you can try and give people on Windows 10 a better experience with your Windows 8.1 app. I briefly tested it on Windows 10 but you would want to do more thorough testing on Windows 8.1 as well:
private void FixUpScale()
{
// Need to add a using for System.Reflection;
var displayInfo = DisplayInformation.GetForCurrentView();
var displayType = displayInfo.GetType();
var rawPixelsProperty = displayType.GetRuntimeProperty("RawPixelsPerViewPixel");
if (rawPixelsProperty != null)
{
var realScale = (double)rawPixelsProperty.GetValue(displayInfo);
// To get to actual Windows 10 scale, we need to convert from
// the de-scaled Win8.1 (100/125) back to 100, then up again to
// the desired scale factor (125). So we get the ratio between the
// Win8.1 pixels and real pixels, and then square it.
var fixupFactor = Math.Pow((double)displayInfo.ResolutionScale /
realScale / 100, 2);
Window.Current.Content.RenderTransform = new ScaleTransform
{
ScaleX = fixupFactor,
ScaleY = fixupFactor
};
}
}

Related

xaml minimum application screen size

how can I set a minimum size in an universal app (win 10) for the application window? in my project I have only object with Page tag, not Window. I want that the screen of the application can't be resized less off a certein value.
thanks a lot
In the Package.appxmanifest of a Windows 8.1 Universal app, you could set a minimum width, to one of 3 pre-defined values. Setting minimum values on your page will not prevent your application from resizing. Setting maximum values will not prevent resizing either, but it will result in black borders when the application frame is larger than your set dimension. It's worth mentioning that 320 px is the absolute minimum width on 8.1 and on Windows 10 (for phones).
In Windows 10 UWP this property is no longer available. You should AdaptiveTriggers to handle your UI layout on Windows 10.
If you want to check the minimum resize dimensions, keep the scaling of your pc in mind. My laptop scales at 125%, a screenshot of the minimum dimension for the desktop client is 627x441 (~500x350 at 100%) including the space used for the app bar. But it's more common to just use AdaptiveTrigger and 720 pixels as the cut-off between phone and tablet.
you are working on a universal app, you shouldn't set a minimum width . It should be working on every resolution and device.
you should instead use visual state manager and adaptive triggers.
best of luck !

Windows Phone 8.1 app always scales images

I have converted one of my Windows Store applications to a universal application and added a Windows Phone project to it.
When rendering the graphics (Image and Rectangles with ImageBrushes) the graphics always gets scaled even if I set it to not scale which is not how expect it to work.
Example:
I have an image that is named test.scale-100.png which is 27*27 pixles.
The same image exists as a 32*32 pixel sized image named test.scale-140.png and another named test.scale-240.png which is 59*59 pixles
I use this image in my default layout the following way:
<Image x:Name="imgTest" Source="/Assets/test.png" Stretch="None"/>
When I start my app with the Windows Phone 8.1 WVGA 4 inch emulator the 32*32 image is shown with the correct bounds, but the actual image is scaled (I can see that quite simple because the content gets blurred).
The same happens when I start the app with the Windows Phone 8.1 1080p 6inch emulator; The image is 59*59 pixles but the image is a bit blurred.
How can I force scaling to not be performed?
Thanks in advance for any help!
I am not sure. I am looking for a solution right now too. But I found that scaling is not supported in Windows Phone 8.1. Only Windows Store apps are working with scaling. Take a look at link below.
http://msdn.microsoft.com/en-us/library/windows/apps/dn263244.aspx
So, the way how to scale images is to use height/width propreties to force size of image or you can use BitmapImage and its property DecodePixelHeight/DecodePixelWidth together with Height/Width properties to decode the image.
Hope it helps ;)
I have the same issue, I think this is an OS bug:
Test 1
test.scale-100.png +
test.scale-140.png +
test.scale-240.png
= Blurry result
Test 2
test.scale-240.png
= Blurry result, again
Test 3
test.scale-240.png renamed to test.png
= Sharp result!
The problem occurs only with certain assets, not all. In my case only in some DataTemplates. I think that in some situations the system scale the image incorrectly, with an horrible blurry result. If you leave only the "scale-240" image, it is blurry. If you rename it removing "scale-240", it becomes sharp!
In summary, name the image as test.png and stop.
As MSDN says:
Don't use images that aren't sized to multiples of 5px. Units that aren't multiples of 5px can experience pixel shifting when scaled to 140%, 180%, and 240%.
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465362.aspx
Your Width="53" Height="53" could be the issue of incorrect behavior

WinRT Surface DirectX Black Screen

I'm having a strange and irritating problem on WinRT Surface tablet when using DirectX (hosted in BackgroundSwapChainPanel). Basically once in a while (like once a day, or few times a week / while testing for few hours every day), half of my 3D scene goes black, like on the picture below (cut vertically or sometimes horizontally):
http://www.zurawcli.vot.pl/dxProblem.JPG
While this happens, the DirectX is still rensponsive and i have full control of the app.
I don't think posting code makes any sense ( i'm simply using standard SwapChain and resizing viewport and back texture whenever screen size changes - actually getting screen size from Core Window). This only happens once in a while : ( when i try to explicitly force this - like by splitting screen between two / switching between apps / and so on, I CANNOT repeat this error - viewport always resizes correctly. Then sometimes just using the app, this will happen.
Did anybody had any experience similliar to this ? Any ideas what is causing this ?
Thanks in advance,
cheers

Why are the maximum X and Y touch coordinates on the Surface Pro is different from native display resolution?

I have noticed that the Surface Pro and I believe the Sony Vaio Duo 11 are reporting maximum touch coordinates of 1366x768, which is surprising to me since their native display resolution is 1920x1080.
Does anyone know of a way to find out at runtime what the maximum touch coordinates are? I'm running a DirectX app underneath the XAML, so I have to scale the touch coordinates into my own world coordinates and I cannot do this without knowing what the scale factor is.
Here is the code that I'm running that looks at the touch coordinates:
From DirectXPage.xaml
<Grid PointerPressed="OnPointerPressed"></Grid>
From DirectXPage.xaml.cpp
void DirectXPage::OnPointerPressed(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
{
auto pointerPoint = args->GetCurrentPoint(nullptr);
// the x value ranges between 0 and 1366
auto x = pointerPoint->Position.X;
// the y value ranges between 0 and 768
auto y = pointerPoint->Position.Y;
}
Also, here is a sample project setup that can demonstrate this issue if run on a Surface Pro:
http://andrewgarrison.com/files/TouchTester.zip
Everything on XAML side is measured in device independent pixels. Ideally you should never have to worry about actual physical pixels and let winrt do its magic in the background.
If for some season you do need to find you current scale factor you can use DisplayProperties.ResolutionScale and use it to convert DIPs into screen pixels.
their native display resolution is 1920x1080
That makes the display fit the HD Tablet profile, everything is automatically scaled by 140%. With of course the opposite un-scaling occurring for any reported touch positions. You should never get a position beyond 1371,771. This ensures that any Store app works on any device, regardless of the quality of its display and without the application code having to help, beyond providing bitmaps that still look sharp when the app is rescaled to 140 and 180%. You should therefore not do anything at all. It is unclear what problem you are trying to fix.
An excellent article that describes the automatic scaling feature is here.

Panorama Background Image is Blurry

I have a Panorama image in my app and when it loads on the phone it is blurry. It's like when you remote desktop into another computer and you have the color settings way down. The gradient is made up of 6 colors and I can count them from the big blocky change.
Is there something special that needs to be done for an image to work as a Panorama background?
I've tried using a JPG and PNG version of the image and it looks the same for either.
I know this is an older post, but with Windows Phone Mango (7.5) you can now specify 32 bit by modifying your manifest.
BitsPerPixel="32"
Add that to the <App xmlns="" ProductID="" BitsPerPixel="32"/> and your images will now display in 32 bit mode. You get a lot smoother gradients and color resolution.
The startup screen still is only 16 bit, and your icons will only really display in 16 bit. But you can get nice colors in your app.
Windows Phone 7 currently renders with 16bit color depth, unlike your desktop/emulator which has a higher color depth. As a result, gradients won't look the same as they do on your desktop PC.
This thread here has some great pointers on how to optimize your images for this environment:
Is there a way to render PNG with gradients in Internet Explorer Mobile 7 correctly?