I've written a Silverlight application that does not scale when I change from 96 dpi to 120 dpi The text and graphics does not change physical size on the screen as measured by a ruler. I've read in various places that Silverlight should adjust to changes in DPI configuration. The non-Silverlight portion of the web page scales as expected. It seems as if the Silverlight plugin is using Pixels as the unit of measure rather than 1/96 inch. What's the explanation?
I'm running Windows XP and setting the DPI in Wndows XPdesktop properties / settings / general / DPI Setting.
This wont help if you're after measurable coordinates (ie: displaying an accurate ruler in your app), but if you want your UI to be resolution independent, you can wrap it with a ViewBox, which is part of the Silverlight Toolkit
Related
I have an application which uses three UI frameworks:
OWL
Windows Forms
WPF
The WinForms and WPF forms and dialogs use fonts that are noticeably smaller than the OWL fonts.
If I use DPI scaling (to 125%) in Windows 10, it does a very good job of upscaling a Windows Forms dialog. If I use Scale on a Windows Form it only scales the controls and not the fonts. If I use the functions suggested here:
https://github.com/Microsoft/WPF-Samples/blob/master/PerMonitorDPI/WinFormsHost/MainWindow.xaml.cs
I get scaled controls but not fonts if I only use the form scaling. If I use the extra font scaling functions, that increases the size of the dialog way beyond the original desired scaling (from 1.25 to 1.6 roughly).
Does anyone know how to scale a WinForms form properly like Windows 10 seems to be able to (without changing screen DPI setting to 125%)?
The answer is to place everything in a flow layout or a table layout. Then spend time figuring out how to make sure they layout correctly.
A better answer would be WPF but that's not always an answer.
I am a bit confused about per-monitor dpi-aware in WPF. I thought you need to do some work to make your windows scale properly on different monitors (as described in Developing a Per-Monitor DPI-Aware WPF Application).
But I've just ran my app on pc with two monitors (2560x1440 and 2160x1440) and the dialogue would automatically scale itself when I move it between monitors. That's on the latest fast ring Windows 10. Am I missing something?
What you see is an example of System scaling when one app window moves to a different monitor with a different DPI. That is because WPF apps are by-default System DPI Aware. As a result, if you notice carefully, you'll see WPF visuals/text gets blurred when the target DPI is higher or they look fuzzy when the target DPI is lower.
Also, note that monitor resolution does not matter for WPF apps, since WPF is device resolution agnostic (it's measurement unit is Device independent Pixels).
Good news : .NET 4.6.2 preview just got released and it hasPer Monitor DPI Awareness out of the box. Check out the developer guide and samples here :
https://github.com/Microsoft/WPF-Samples/tree/master/PerMonitorDPI
Continuing the conversation from comments.
Yes that is the same for Windows 8.1.
And here is the note from your linked post
Windows Presentation Foundation (WPF) applications are by default system DPI-aware.
HTH
I have WPF application work with 1024x768 screen resolution, now I want to run this application on Microsoft Surface with wide resolution, I had make new windows with resolution 1366x768, but unfortunately I can't make it work fine on Surface, I tested it on my laptop, it's work 100%, but I don't understand why it would't work in the same way on Surface.
If there is anyone that has experience with Surface can you please help?
Update
When I run the WPF windows with resolution 1920x1080 work full screen on my laptop, but the problem is when run application on Surface with the same resolution don't fit the full screen, see this screenshot to more clarity:
Maybe your surface and laptop have different DPI settings. See here how to handle that problem.
From the information provided it may be that your WPF window layout doesn't sufficiently take into account differences in Display text and item sizing on different devices.
On both your Surface Pro and your laptop:
Select "Screen Resolution" from the Desktop context menu.
Select "Make text and other items larger or smaller" from the Screen
Resolution window.
Check the position of the "Change the size of all items" slider.
By default the Surface Pro is set to Larger. A new Windows 8 install will be set to Smaller.
In WPF you should not be setting a constant window size, instead you should:
Make the window's content react to the window size by using auto sizes and grids instead of constant sizes and panels
You can use WindowState="Maximized" to make the window full screen
You can prevent your window from being reduced too much with minwidth and minheight.
With my current monitor I prefer a DPI setting of 120 pixels per inch (which windows suggests as the default). However, after designing a form, it often lays out incorrectly on systems that don't use 120 pixels per inch.
I'm wondering, is it necessary that I should set my display settings to 96 pixels per inch for whenever I use the designer?
Also, there are some problems when other developers have different DPIs. They open a form in the designer and move something like a text edit control, and suddenly find that it automatically resizes itself too. Then, there's one control that's a different size to the others and we're in a mess.
P.S. I've read related posts. They're all interesting, but didn't answer my question.
How to control the font DPI in .NET WinForms app
C# WinForms disable DPI scaling
WinForms Different DPI Layouts
DPI not scaling properly
Visual Studio and DPI issue
No. You don't need to always have the DPI set to 96 when using the WinForms designer.
If you set the AutoScaleMode property to Dpi then the designer will write the current system DPI into the designer.cs file in the AutoScaleDimensions property for the form. When the designer is used on a system with a different DPI, this information will be used to rescale the form and the designer can be used at a different DPI.
When I tried other scaling modes, this didn't seem to work well. 'None' meant that controls wouldn't scale at runtime, 'Font' seemed to suffer from rounding errors and when the display settings DPI changed, the control sizes could change slightly causing errors.
I also found that for UserControls that are added to forms it is best to set their AutoScaleMode to Inherit. If you use Dpi, then the controls on it get re-scaled twice and will end up being laid out incorrectly.
I came up with the guidelines above after a few hours of experimentation and internet searching where I found the following two articles:
Automatic scaling in Windows Forms
and:
Child controls on a UserControl may get clipped in a system with a lower Font Dpi
I don't think setting your dpi to a different value permanently will help you. The problem is that there are problems when you change the dpi, i.e. the form layout you have isn't able to deal with different dpi's.
I don't have an absolute solution for you, except that you should test with different dpis and see if it produces problems with the form display. It isn't hard to work out what causes problems and you'll learn what to avoid fairly quickly.
I am working on silverlight application and finding the DPI of Canvas.
so how I can find it.
Thanks.
All measurements in Silverlight are in logical pixels where there are 96 DPI, regardless of the actual DPI of the device being rendered on.