如何从xaml获取屏幕尺寸?
我在C#上使用wpf来设计GUI,我想从xaml代码中获取屏幕大小(宽度和高度的值)。
我知道如何从C#代码中获取它们
Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
但我不知道如何从XAML
代码中获取它们。
这会奏效。 您可以在此处阅读有关SystemParameters的更多信息
查看SystemParameters类: http : //msdn.microsoft.com/de-de/library/system.windows.systemparameters.fullprimaryscreenheight.aspx
你可以像这样使用它:
(您也可以使用x:Static表示法来查询Windows窗体属性,但是如果您正在开发WPF应用程序,则可能需要使用SystemParameters类)
假设您的XAML中的父容器是网格,将其命名为grdForm
在后面的代码中可以得到维度
double width = grdForm.ActualWidth
double height = grdForm.ActualHeight