diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 31622c5fe..8e9d46056 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -95,6 +95,10 @@ { "source_path": "docs/whats-new/dotnet-7.md", "redirect_url": "/dotnet/maui/whats-new/dotnet-8" + }, + { + "source_path": "docs/fundamentals/windows.md", + "redirect_url": "/dotnet/maui/user-interface/controls/window" } ] } diff --git a/docs/TOC.yml b/docs/TOC.yml index 5ff6ce980..c017257a7 100644 --- a/docs/TOC.yml +++ b/docs/TOC.yml @@ -247,8 +247,6 @@ href: fundamentals/datatemplate.md - name: Triggers href: fundamentals/triggers.md - - name: Windows - href: fundamentals/windows.md - name: User interface items: - name: Animation @@ -443,6 +441,8 @@ href: user-interface/controls/twopaneview.md - name: WebView href: user-interface/controls/webview.md + - name: Window + href: user-interface/controls/window.md - name: C# markup href: /windows/apps/windows-dotnet-maui/tutorial-csharp-ui-maui-toolkit?toc=/dotnet/maui/toc.json&bc=/dotnet/maui/breadcrumb/toc.json - name: Display pop-ups diff --git a/docs/migration/includes/api-changes.md b/docs/migration/includes/api-changes.md index ef01ad833..9193bf342 100644 --- a/docs/migration/includes/api-changes.md +++ b/docs/migration/includes/api-changes.md @@ -149,7 +149,7 @@ A small number of other APIs have been consolidated in the move from Xamarin.For > | `Xamarin.Forms.Span.ForegroundColor` | | | > | `Xamarin.Forms.ToolbarItem.Name` | | is the base class for , and so `ToolbarItem.Name` becomes `ToolbarItem.Text`. | -In addition, in Xamarin.Forms, the `Page.OnAppearing` override is called on Android when an app is backgrounded and then brought to the foreground. However, this override isn't called on iOS and Windows in the same scenario. In .NET MAUI, the override isn't called on any platforms when an app is backgrounded and then brought to the foreground. Instead, you should listen to lifecycle events on to be notified when an app returns to the foreground. For more information, see [.NET MAUI windows](~/fundamentals/windows.md). +In addition, in Xamarin.Forms, the `Page.OnAppearing` override is called on Android when an app is backgrounded and then brought to the foreground. However, this override isn't called on iOS and Windows in the same scenario. In .NET MAUI, the override isn't called on any platforms when an app is backgrounded and then brought to the foreground. Instead, you should listen to lifecycle events on to be notified when an app returns to the foreground. For more information, see [.NET MAUI windows](~/user-interface/controls/window.md). ### Native forms changes diff --git a/docs/fundamentals/windows.md b/docs/user-interface/controls/window.md similarity index 96% rename from docs/fundamentals/windows.md rename to docs/user-interface/controls/window.md index b45804618..0f6c059fe 100644 --- a/docs/fundamentals/windows.md +++ b/docs/user-interface/controls/window.md @@ -1,10 +1,10 @@ --- -title: ".NET MAUI windows" +title: "Window" description: "Learn how to use the .NET MAUI Window class to create, configure, show, and manage multi-window apps." -ms.date: 08/09/2024 +ms.date: 01/17/2025 --- -# .NET MAUI windows +# Window The .NET Multi-platform App UI (.NET MAUI) class provides the ability to create, configure, show, and manage multiple windows. @@ -39,7 +39,7 @@ The class defines the following events: - , with an accompanying `BackgroundingEventArgs` object, which is raised on iOS and Mac Catalyst when the window is closed or enters a background state. This event can be used to persist any `string` state to the `State` property of the `BackgroundingEventArgs` object, which the OS will preserve until it's time to resume the window. When the window is resumed the state is provided via the `IActivationState` argument to the `CreateWindow` method. - , with an accompanying `DisplayDensityChangedEventArgs` object, which is raised on Android and Windows when the effective dots per inch (DPI) for the window has changed. -For more information about the lifecycle events, and their associated overrides, see [App lifecycle](app-lifecycle.md). +For more information about the lifecycle events, and their associated overrides, see [App lifecycle](~/fundamentals/app-lifecycle.md). The class also defines the following modal navigation events: @@ -230,11 +230,21 @@ Then, in the XML editor, open the **Platforms > iOS > Info.plist** file and the ## Position and size a Window +::: moniker range="=net-maui-8.0" + The position and size of a window can be programmatically defined for a .NET MAUI app on Windows by setting the `X`, `Y`, `Width`, and `Height` properties on a object. > [!WARNING] > Mac Catalyst doesn't support resizing or repositioning windows programmatically by setting the `X`, `Y`, `Width`, and `Height` properties. +::: moniker-end + +::: moniker range=">=net-maui-9.0" + +The position and size of a window can be programmatically defined for a .NET MAUI app on Mac Catalyst and Windows by setting the `X`, `Y`, `Width`, and `Height` properties on a object. + +::: moniker-end + For example, to set the window position and size on launch you should override the `CreateWindow` method in your `App` class and set the `X`, `Y`, `Width`, and `Height` properties on a object: ```csharp @@ -269,6 +279,8 @@ Window.Y = (displayInfo.Height / displayInfo.Density - Window.Height) / 2; For information about obtaining the device's screen metrics, see [Device display information](~/platform-integration/device/display.md). +::: moniker range="=net-maui-8.0" + ### Mac Catalyst Mac Catalyst doesn't support resizing or repositioning windows programmatically. However, a workaround to enable resizing is to set the `MinimumWidth` and `MaximumWidth` properties to the desired width of the window, and the `MinimumHeight` and `MaximumHeight` properties to the desired height of the window. This will trigger a resize, and you can then revert the properties back to their original values: @@ -289,6 +301,8 @@ Dispatcher.Dispatch(() => }); ``` +::: moniker-end + ## Decouple window management from the App class Window management can be decoupled from the `App` class by creating a class that implements the interface, and adding your window management code in the method: diff --git a/docs/whats-new/dotnet-8.md b/docs/whats-new/dotnet-8.md index f3aea20b6..121514066 100644 --- a/docs/whats-new/dotnet-8.md +++ b/docs/whats-new/dotnet-8.md @@ -70,7 +70,7 @@ While the focus of this release of .NET MAUI is quality, there's also some new f ### Miscellaneous -- Window management can be decoupled from the `App` class. For more information, see [Decouple window management from the App class](~/fundamentals/windows.md#decouple-window-management-from-the-app-class). +- Window management can be decoupled from the `App` class. For more information, see [Decouple window management from the App class](~/user-interface/controls/window.md#decouple-window-management-from-the-app-class). - Several system fonts can be easily consumed in Android apps. For more information, see [Consume fonts](~/user-interface/fonts.md#consume-fonts). - On iOS, `MauiUIApplicationDelegate` gains a `PerformFetch` method that can be overridden or consumed via the `iOSLifecycle.PerformFetch` delegate. For more information, see [iOS and Mac Catalyst platform lifecycle events](~/fundamentals/app-lifecycle.md#ios-and-mac-catalyst). diff --git a/docs/whats-new/dotnet-docs-maui-mod2.md b/docs/whats-new/dotnet-docs-maui-mod2.md index 1b7ec68fe..12b1303c2 100644 --- a/docs/whats-new/dotnet-docs-maui-mod2.md +++ b/docs/whats-new/dotnet-docs-maui-mod2.md @@ -33,7 +33,7 @@ Welcome to what's new in the .NET Multi-platform App UI (.NET MAUI) docs for Nov ### Updated articles - [.NET MAUI Shell search](../fundamentals/shell/search.md) -- [.NET MAUI windows](../fundamentals/windows.md) +- [.NET MAUI window](../user-interface/controls/window.md) - [App lifecycle](../fundamentals/app-lifecycle.md) - [Compiled bindings](../fundamentals/data-binding/compiled-bindings.md) - [Control templates](../fundamentals/controltemplate.md)