如何在 Xamarin Cocoa 应用程序中获取设备宽度和高度

How to get device width and height in Xamarin Cocoa apps

我正在 Xamarin 中为 OSX 开发一个 cocoa 应用程序。我在设置 window/form 的 100% 宽度时遇到问题,以便它应该占据屏幕的整个宽度。有什么方法可以检测屏幕宽度,以便我可以在 C# 中以编程方式设置宽度?

使用 NSWindow 实例的 Screen.Frame 属性 获取屏幕尺寸。使用 SetFrame 方法

设置 NSWindow 实例大小
var screenFrame = window.Screen.Frame;
window.SetFrame( new CGRect(0, 0, screenFrame.Width, 400), true, true );