I have been working on WPF desktop application and have graphics according to a particular screen resolution. I need to scale the all the margins based on screen resolution. How can I achieve this?
0
votes
3 Answers
1
votes
0
votes
To get the Screen Resolutions we have to use the dpi factor value of system, use the below code as per this article (please read it in full to understand):
using System.Windows.Media;
Window mainWindow = Application.Current.MainWindow;
PresentationSource mainWindowPresentationSource = PresentationSource.FromVisual(mainWindow);
Matrix m = mainWindowPresentationSource.CompositionTarget.TransformToDevice;
double dpiWidthFactor = m.M11;
double dpiHeightFactor = m.M22;
double ScreenHeight = SystemParameters.PrimaryScreenHeight * dpiHeightFactor; //calculated correct value
double ScreenWidth = SystemParameters.PrimaryScreenWidth * dpiWidthFactor; //calculated correct value