【发布时间】:2018-11-21 21:23:43
【问题描述】:
我一直在开发 WPF 桌面应用程序,并根据特定的屏幕分辨率制作图形。我需要根据屏幕分辨率缩放所有边距。我怎样才能做到这一点?
【问题讨论】:
-
该链接回答了多屏问题,我现在不在乎多屏,您的评论中的“this”指的是什么,它不是链接
标签: wpf
我一直在开发 WPF 桌面应用程序,并根据特定的屏幕分辨率制作图形。我需要根据屏幕分辨率缩放所有边距。我怎样才能做到这一点?
【问题讨论】:
标签: wpf
你可以使用:
System.Windows.SystemParameters.PrimaryScreenWidth;
System.Windows.SystemParameters.PrimaryScreenHeight;
搜索一下 :)
【讨论】:
要得到Screen Resolutions,我们必须使用系统的dpi因子值,使用下面的代码this article(请阅读完整的理解):
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
【讨论】:
添加对 :- System.Windows.Forms 的引用
var width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
【讨论】: