簡體   English   中英

如何獲取 WinUI 3 桌面應用程序的屏幕邊界?

[英]How to get screen bounds for WinUI 3 Desktop application?

我需要在 WinUI 3 桌面應用程序中實現以下要求。

  1. 如何獲得屏幕邊界?
  2. 如何在運行時更改 windows cursor 類型?

我已經在 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));

對於 Cursor:

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

任何人請建議如何在 WinUI 桌面應用程序中實現相同的要求?

我在 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();
}      

當我在任何地方需要邊界時,我可以使用MainWindow.Bounds

關於 cursor,你需要ProtectedCursor

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

只有它受到保護,所以您需要從正確的 class 使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM