Modal windows for desktop apps #840
Replies: 5 comments 7 replies
-
Created initial feature proposal here: #842 |
Beta Was this translation helpful? Give feedback.
-
It can be achieved by Popup. Why do you need a new window? |
Beta Was this translation helpful? Give feedback.
-
A modal may be required when we want to ensure that this flow is completed before another interaction, especially where we need a confirmation before any future action is taken. Also, we would like to prevent background or offscreen popups from collecting in general. |
Beta Was this translation helpful? Give feedback.
-
Thanks for discussing during the February 2023 .NET MAUI Community Toolkit Monthly Standup. Some further input on potential handling on non-desktop platforms. Looking at features for building great desktop apps, and how those are handled in MAUI, the APIs and/or types are exposed to all TFMs but are ignored (or fail silently) on platforms where they're not suitable/supported. On this basis, developers would either do nothing or handle the flow/UI differently based on whether they're targeting mobile or desktop. However, in this case, the current INavigation.PushModalAsync behavior feels like a suitable fallback for those platforms that don't support multi-window (and modal windows). As a starting point, one approach might be to extend INavigation with a version of INavigation.PushModalAsync that will show the specified Page in a modal Window if supported but otherwise use the current method to display it within the current Window. Indicative implementationnamespace Microsoft.Maui.Controls;
public static class INavigationExtensions
{
public static Task PushModalAsyncEx(this INavigation navigation, Page page)
{
#if MACCATALYST || WINDOWS
Application.Current.OpenWindow(new ModalWindow(page));
return Task.CompletedTask;
#else
return navigation.PushModalAsync(page);
#endif
}
} Indicative usagepublic partial class MainPage : ContentPage
{
void OnButtonClicked(object sender, EventArgs e)
=> Navigation.PushModalAsyncEx(new MyPage());
} Further considerationsAssuming demand continues to grow within the community for desktop focused features, one approach to consider in future might be splitting those capabilities out into a standalone version of the toolkit specific to desktop. For example, CommunityToolkit.Maui.Desktop. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Closed as answered. |
Beta Was this translation helpful? Give feedback.
-
Ability to display a traditional desktop modal window in a .NET MAUI app that:
Existing options, within .NET MAUI and other third-party components, only support the display of a Page and/or dialog that is constrained to the Window it was opened from.
The expectation is that this requires use of the following platform-specific APIs.
MacCatalyst
A modal event loop can be started and stopped for a specific NSWindow using the following APIs from the NSApplication class:
While the NSApplication and NSWindow types cannot be used directly in MacCatalyst, it's possible to get a reference to those types and invoke the requisite functionality on them via selectors.
WinUI3
There's an open proposal for adding modal dialog support to WinUI3 but it does not currently support this concept directly. However, the requirements might be achieved through a combination of Win32 and Windows App SDK Interop APIs alongside the Windows App SDK components as described in an answer to a recent forum question. Notable members, types, and APIs include:
Types and Members
WIn32 APIs and Constants
Would others consider this a valuable addition to the Community Toolkit?
Beta Was this translation helpful? Give feedback.
All reactions