dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

When updating MAUI to WinAppSDK 1.4 PInvoke.SetParent no longer works #20253

Open PureWeen opened 8 months ago

PureWeen commented 8 months ago

Description

The behavior described in this issue will no longer work https://github.com/dotnet/maui/issues/17490 once users update to 1.4 WinAppSDK. From conversations with WinAppSDK it sounds like it was never really supposed to work at all.

I'm using this space as a place to understand current use cases so that we can inform WinAppSDK about what we are hoping for in later versions of WinAppSDK.

Some of this behavior currently can be achieved via https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.hosting.desktopwindowxamlsource?view=winrt-22621

I don't really have specifics on how yet :-) I still need to figure it out for myself.

danielancines commented 8 months ago

Hi @PureWeen , I using on a Maui app, to recreate a MDI experience. My repo: https://github.com/danielancines/Maui-SetParentError-dotnet8Rc1 has an example.

I created an full working MDI project, with MDIChild and MDIParent.

Let me know if you need more info about it.

danielancines commented 8 months ago

I updated my repo to Maui 8.0.6 and it's working, but I have some concerns about this:

The behavior described in this issue will no longer work https://github.com/dotnet/maui/issues/17490 once users update to 1.4 WinAppSDK. From conversations with WinAppSDK it sounds like it was never really supposed to work at all.

SetParent is very import for the project that I was working on since 2022, I hope that continues to working because the core of the app is the MDI concept.

The other situation I've got here is, according this issue, when you describe a workaround about resizing Maui window, I tried to update the WinAppSDK as you described there, and the problem with SetParent occurs again.

I'm very worried about this, because it's a huge red flag to update my app to dotnet 8.

lfmouradasilva commented 8 months ago

I'm very worried about this. This feature is extremely important for my application, any updates?

PureWeen commented 8 months ago

@danielancines @lfmouradasilva do you have a short video you can upload of your app using SetParent?

danielancines commented 7 months ago

SetParentExample It from my repo

danielancines commented 7 months ago

Hi guys, any updates? We are thrilled to update to dotnet 8, but without this fix, we can't do it. :-(

PureWeen commented 7 months ago

@danielancines unfortunately this is out of the .NET MAUI teams hands.

As it turns out SetParent was never really supposed to work, it's a fluke that it ever did so the WinAppSDK team isn't really compelled to fix SetParent at this point. The hope is to provide more correct APIs in the future.

We had a few Modal scenarios using SetWindowLongPtr that we've been able to replace by use AppWindow.Create

I'm not sure if this will work for your scenario but here are some notes on the new APIs

Starting with WinAppSDK 1.4, AppWindow exposes a constructor that allows one to specify an owner for the new window https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.windowing.appwindow.create?view=windows-app-sdk-1.4#microsoft-ui-windowing-appwindow-create(microsoft-ui-windowing-appwindowpresenter-microsoft-ui-windowid) . The same overload allows one to specify an AppWindowPresenter for the new window https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.windowing.overlappedpresenter.createfordialog?view=windows-app-sdk-1.4#microsoft-ui-windowing-overlappedpresenter-createfordialog. Once you have a dialog owned by the XAML window in your app, the DesktopWindowXamlSource https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.hosting.desktopwindowxamlsource?view=windows-app-sdk-1.4 allows one to host XAML content in that dialog. The sample referenced earlier in this thread shows an example for how to host XAML content in a window. Next you’ll still need to figure out Modal and the Dispatcher for the dialog but that can go several ways depending on the constraints for your scenario. Hopefully these pointers will get you started.

lfmouradasilva commented 7 months ago

@PureWeen Thank you for the detailed explanation regarding the change in support for the SetParent method and the suggestion to use AppWindow.Create. I'm interested in learning more about how to integrate this approach into a .NET MAUI 8 application.

Would it be possible to provide a code example demonstrating how to use AppWindow.Create in conjunction with .NET MAUI 8? I'm particularly interested in understanding how you've successfully replaced certain scenarios using AppWindow.Create.

Thank you in advance for your assistance and guidance.

danielancines commented 7 months ago

Hi @PureWeen, thanks for your reply, but as far I know, this solution doesn't make the new window child like MDI strategy, the AppWindow idea is bound the child window to another window, to create Modal, Context and other window types. SetParent is used by WinForms since the begining and still working on dotnet 8, do you have any idea how to accomplish WinForms behavior in the latest dotnet Frameworks like WinUI, UWP and Maui?

danielancines commented 7 months ago

Hey @PureWeen , how are you?

I'm testing some scenarios about this issue and let me know about my last tests:

On my testing repo, I combine all existing scenarios to get some insights about what happend, and this is what I found so far:


Branch: tests/v8.0.7-1.5.240227000 Latest dotnet 8 version, maui and Windows App Sdk version 1.5.240227000

Known issues:


Now, I got the v8.0.7 tag from Dotnet Maui repo, build it and using Windows App Sdk 1.5.240227000, Set Parent is working fine and I'm able to close the child Window, no issues so far.

Here you can see what I did for this last sucessfull test.