Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Windows] The second popup will fail to show after MAUI 8.0.60 #1931

Closed
2 tasks done
GuidoNeele opened this issue Jun 13, 2024 · 5 comments · Fixed by #1932
Closed
2 tasks done

[BUG] [Windows] The second popup will fail to show after MAUI 8.0.60 #1931

GuidoNeele opened this issue Jun 13, 2024 · 5 comments · Fixed by #1932
Labels
bug Something isn't working unverified

Comments

@GuidoNeele
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

This is a very strange issue. Since MAUI version 8.0.60 the second popup will fail. Only the second time you want to show a popup will fail. The popup will not show up and if you are using CommunityToolkit.MVVM [RelayCommand] the button (triggering the popup) will be disabled, because the Task will not return. See video of the problem.

Every_second_popup_via_popupservice_fails.mp4

Expected Behavior

The popup should always be shown also the second popup.

Steps To Reproduce

  1. Download latest version of CommunityToolkit
  2. Open Directory.Build.props in root folder of project
  3. Change MauiPackageVersion property to 8.0.60
  4. Open Visual Studio and run the sample application
  5. Go to Views / Multiple Popups Page
  6. Click on "Simple Popup"
  7. Close the popup by clicking outside the popup
  8. Click on "C# Binding Popup"
  9. The button will be disabled and the popup will not appear

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui

Environment

- .NET MAUI CommunityToolkit: 9.0.1
- OS: Windows 11 (net8.0-windows10.0.19041.0)
- .NET MAUI: 8.0.60

Anything else?

To prevent the button from disabling while using CommunityToolkit.MVVM is to use [RelayCommand(AllowConcurrentExecutions = true)] instead of [RelayCommand]

@GuidoNeele GuidoNeele added bug Something isn't working unverified labels Jun 13, 2024
@GuidoNeele GuidoNeele changed the title [BUG] The second popup will fail to show after MAUI 8.0.60 [BUG] [Windows] The second popup will fail to show after MAUI 8.0.60 Jun 13, 2024
@GuidoNeele
Copy link
Contributor Author

Tracked this issue down to the Loaded event not getting triggered, resulting in the taskCompletionSource not completing, which will keep the task running.

var taskCompletionSource = new TaskCompletionSource<object?>();
async void handler(object? sender, EventArgs args)
{
page.GetCurrentPage().Loaded -= handler;
try
{
var result = await CreateAndShowPopupAsync(page, popup, token);
taskCompletionSource.TrySetResult(result);
}
catch (Exception ex)
{
taskCompletionSource.TrySetException(ex);
}
}
page.GetCurrentPage().Loaded += handler;
return taskCompletionSource.Task.WaitAsync(token);

Think this issue is caused by this fix dotnet/maui@21620dc which is included in 9.0.0-preview.5.24307.10 and 8.0.60

This is not an issue on Android. Didn't test on other platforms.

@GuidoNeele
Copy link
Contributor Author

GuidoNeele commented Jun 13, 2024

Issue is fixed if the Unload event is set too.

var taskCompletionSource = new TaskCompletionSource<object?>();

void unloadedHandler(object? sender, EventArgs args) => {};

async void loadedHandler(object? sender, EventArgs args)
{
	page.GetCurrentPage().Unloaded -= unloadedHandler;
	page.GetCurrentPage().Loaded -= loadedHandler;

	try
	{
		var result = await CreateAndShowPopupAsync(page, popup, token);

		taskCompletionSource.TrySetResult(result);
	}
	catch (Exception ex)
	{
		taskCompletionSource.TrySetException(ex);
	}
}

page.GetCurrentPage().Unloaded += unloadedHandler;
page.GetCurrentPage().Loaded += loadedHandler;

return taskCompletionSource.Task.WaitAsync(token);

@bijington
Copy link
Contributor

Any chance the issue relates to this microsoft/microsoft-ui-xaml#1900

@PureWeen
Copy link
Contributor

This fix should be available on the nightly feed as version 8.0.61-ci.net8.24319.3.

Can you test with the latest nightly build?
https://github.com/dotnet/maui/wiki/Nightly-Builds

@GuidoNeele
Copy link
Contributor Author

Hi @PureWeen,

Just tried the nightly build and it indeed fixes the issue.
Thanks for the swift fix!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working unverified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants