0
votes

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?

3
The link answers for multi-screen problem and I dont care abut multi screen as of now and what does "this" refers to in your comment, its not a link - androider

3 Answers

1
votes

you can use :

System.Windows.SystemParameters.PrimaryScreenWidth;
System.Windows.SystemParameters.PrimaryScreenHeight;

make a little search :)

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
0
votes

Add reference to :- System.Windows.Forms

var width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;