Skip to content

Commit

Permalink
Window positioning and sizing now available on Mac Cat (#2741)
Browse files Browse the repository at this point in the history
* Move file.

* Fix links.

* Add redirect.

* Window positioning now on Mac Cat.
  • Loading branch information
davidbritch authored Jan 17, 2025
1 parent 77734ee commit f82db70
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
4 changes: 2 additions & 2 deletions docs/TOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/migration/includes/api-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ A small number of other APIs have been consolidated in the move from Xamarin.For
> | `Xamarin.Forms.Span.ForegroundColor` | <xref:Microsoft.Maui.Controls.Span.TextColor?displayProperty=fullName> | |
> | `Xamarin.Forms.ToolbarItem.Name` | <xref:Microsoft.Maui.Controls.MenuItem.Text?displayProperty=fullName> | <xref:Microsoft.Maui.Controls.MenuItem.Text?displayProperty=fullName> is the base class for <xref:Microsoft.Maui.Controls.ToolbarItem?displayProperty=fullName>, 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 <xref:Microsoft.Maui.Controls.Page.OnAppearing> 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 <xref:Microsoft.Maui.Controls.Window> 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 <xref:Microsoft.Maui.Controls.Page.OnAppearing> 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 <xref:Microsoft.Maui.Controls.Window> 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

Expand Down
Original file line number Diff line number Diff line change
@@ -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) <xref:Microsoft.Maui.Controls.Window> class provides the ability to create, configure, show, and manage multiple windows.

Expand Down Expand Up @@ -39,7 +39,7 @@ The <xref:Microsoft.Maui.Controls.Window> class defines the following events:
- <xref:Microsoft.Maui.Controls.Window.Backgrounding>, 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.
- <xref:Microsoft.Maui.Controls.Window.DisplayDensityChanged>, 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 <xref:Microsoft.Maui.Controls.Window> class also defines the following modal navigation events:

Expand Down Expand Up @@ -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 <xref:Microsoft.Maui.Controls.Window> 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 <xref:Microsoft.Maui.Controls.Window> 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 <xref:Microsoft.Maui.Controls.Window> object:

```csharp
Expand Down Expand Up @@ -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:
Expand All @@ -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 <xref:Microsoft.Maui.Controls.IWindowCreator> interface, and adding your window management code in the <xref:Microsoft.Maui.Controls.IWindowCreator.CreateWindow%2A> method:
Expand Down
2 changes: 1 addition & 1 deletion docs/whats-new/dotnet-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
2 changes: 1 addition & 1 deletion docs/whats-new/dotnet-docs-maui-mod2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f82db70

Please sign in to comment.