Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
Cómo maximizar, minimizar y restaurar la ventana de WinUI desde el código

Estoy creando una aplicación de demostración con la versión preliminar 0.5 de WinUI 3 (reunión del proyecto).

Me gustaría maximizar, minimizar y restaurar el estado de la ventana desde el código administrado de C#. ¿Hay ejemplos disponibles?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Aparentemente, esto no es posible usando código administrado en este momento. PInvoke es la única opción actualmente. Usé el paquete nuget PInvoke.User32.

over 4 years ago · Santiago Trujillo Report

0

Use la clase AppWindow del SDK de aplicaciones de Windows

 // Retrieve the window handle (HWND) of the current (XAML) WinUI 3 window. IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this); // Retrieve the WindowId that corresponds to hWnd. WindowId windowId = Win32Interop.GetWindowIdFromWindow(hWnd); // Lastly, retrieve the AppWindow for the current (XAML) WinUI 3 window. AppWindow appWindow = AppWindow.GetFromWindowId(windowId); appWindow.Closing += AppWindow_Closing;
 private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args) { args.Cancel = true; }

https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/windowing/windowing-overview

over 4 years ago · Santiago Trujillo Report

0

Aquí está mi implementación basada en el paquete nuget PInvoke.User32.

Versión usando el parámetro de ventana

 public void MaximizeWindow(Window window) { var windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window); PInvoke.User32.ShowWindow(windowHandle, PInvoke.User32.WindowShowStyle.SW_MAXIMIZE); }

Versión usando el método de extensión

Este código anterior también se puede transformar en un método de extensión para la clase Window , por lo que puedo llamar a this.Maximize() desde la Window :

 public static class WindowExtensions { public static void Maximize(this Window window) { var windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window); PInvoke.User32.ShowWindow(windowHandle, PInvoke.User32.WindowShowStyle.SW_MAXIMIZE); } }

Uso en su clase derivada de Windows:

esto.Maximizar();


Minimizar y Restaurar

La definición "PInvoke.User32.WindowShowStyle" utilizada en los ejemplos anteriores también contiene constantes para SW_MINIMIZE y SW_RESTORE , pero no probé esto.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!