6

我需要在 WinUI 3 桌面应用程序中实现以下要求。

  1. 如何获得屏幕边界?
  2. 如何在运行时更改 Windows 光标类型?

我已经在 WinUI UWP 应用程序中这样做了。

对于屏幕边界,

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));

对于光标:

Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeNorthwestSoutheast, 0);

任何人请建议如何在 WinUI 桌面应用程序中实现相同的要求?

4

1 回答 1

0

I've added the following to 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.

Regarding cursor, you need ProtectedCursor

this.ProtectedCursor = InputSystemCursor.Create(InputSystemCursorShape.Arrow);

Only thing it is protected, so you need to use it from right class.

于 2021-12-15T12:14:14.787 回答