[英]How to get screen bounds for WinUI 3 Desktop application?
I need to achieve below requirements in WinUI 3 Desktop applications.我需要在 WinUI 3 桌面应用程序中实现以下要求。
I already did this in WinUI UWP applications.我已经在 WinUI UWP 应用程序中这样做了。
For Screen bounds,对于屏幕边界,
var visibleBounds = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds;
var scaleFactor = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
Size screenSize = new Size((visibleBounds.Width * scaleFactor), (visibleBounds.Height * scaleFactor));
For Cursor:对于 Cursor:
Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeNorthwestSoutheast, 0);
Anyone please suggest how to achieve same requirement in WinUI Desktop applications?任何人请建议如何在 WinUI 桌面应用程序中实现相同的要求?
I've added the following to App.xaml.cs:我在 App.xaml.cs 中添加了以下内容:
private static MainWindow m_window;
public static MainWindow MainWindow { get { return m_window; } }
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e)
{
m_window = new MainWindow();
m_window.Activate();
}
And when I need bounds anywhere, I can use MainWindow.Bounds
.当我在任何地方需要边界时,我可以使用
MainWindow.Bounds
。
Regarding cursor, you need ProtectedCursor
关于 cursor,你需要
ProtectedCursor
this.ProtectedCursor = InputSystemCursor.Create(InputSystemCursorShape.Arrow);
Only thing it is protected, so you need to use it from right class.只有它受到保护,所以您需要从正确的 class 使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.