【问题标题】:How to get screen bounds for WinUI 3 Desktop application?如何获取 WinUI 3 桌面应用程序的屏幕边界?
【发布时间】:2021-05-13 07:19:16
【问题描述】:

我需要在 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 桌面应用程序中实现相同的要求?

【问题讨论】:

    标签: desktop .net-5 winui-3


    【解决方案1】:

    我已将以下内容添加到 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

    关于光标,你需要ProtectedCursor

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

    只有它受到保护,所以你需要从正确的类中使用它。

    【讨论】:

      猜你喜欢
      • 2022-10-14
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 2022-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多