-
Notifications
You must be signed in to change notification settings - Fork 486
Description
Describe the bug
I am trying to use SnackBar in my application. My application supports multiple windows.
There appears to be an issue upon closing a second windows.
Here is a link to the repo:
https://github.com/McSaverInvestments/TestToolKit2
Steps to reproduce
******* Steps to set up Test MAUI Application which demostrates the bug ***********************
1) Inside of visual studio(Version 17.12.0 Preview 2.1) create a new .Net Maui App called TestToolKit2
Note: The Preview version of visual studio is irrelevant
Using .NET 8 long term support
2) Add a Dependency for the CommunityToolkit.MAUI to the new project
3) To support SnackBar, Modify the Package.appxmaniest file in the Platforms.Windows folder
a) Change Line 7 to the following
IgnorableNamespaces="uap rescap com desktop">
b) Add the following after (Line 6 and before Line 7)
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
c) Add the following after Line 40 (</uap:VisualElements>)
<Extensions>
<!-- Specify which CLSID to activate when notification is clicked -->
<desktop:Extension Category="windows.toastNotificationActivation">
<desktop:ToastNotificationActivation ToastActivatorCLSID="6e919706-2634-4d97-a93c-2213b2acc334" />
</desktop:Extension>
<!-- Register COM CLSID -->
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="TestToolKit2\TestToolKit2.exe" DisplayName="$targetnametoken$" Arguments="----AppNotificationActivated:">
<com:Class Id="6e919706-2634-4d97-a93c-2213b2acc334" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
</Extensions>
4) Add the following to MauiProgram.cs after the builder's .UseMauiApp<App>() line of code (Line 12)
.UseMauiCommunityToolkit(options =>
{
// BUG: Application crashes when a true is passed
options.SetShouldEnableSnackbarOnWindows(true);
})
NOTE: don't forget to add the following to the top of MauiProgram.cs
using CommunityToolkit.Maui;
4) Add the following button to MainPage.xaml (on Line 33)
<Button
x:Name="OpenWndBtn"
Text="Open Window"
SemanticProperties.Hint="Open a window when you click"
Clicked="OnOpenWndClicked"
HorizontalOptions="Fill" />
5) Add the following code to MainPage.xaml.cs (after Line 11)
private void OnOpenWndClicked(object sender, EventArgs e)
{
TestWindow.OpenNewWindow(new TestWindow());
}
6) Add a new item (TestWindow.cs) to the project and replace the code with the following
namespace TestToolKit2
{
internal class TestWindow : Window
{
#region Static - Methods
public static void OpenNewWindow<TWindow>(TWindow aWindow)
where TWindow : Window
{
Application.Current!.OpenWindow(aWindow);
}
#endregion
public TestWindow()
{
Page = new TestPage();
}
}
}
7) Add a new .NET MAUI ContentPage (XAML) called TestPage.xaml to the project
NOTE: the default generated code supplied by Visual Studio is fine.
// ****** Steps to produce the error *********************
//
// Note: Using true in the follow line of CreateMauiApp() causes the error to occurs
// options.SetShouldEnableSnackbarOnWindows(true);
//
// Steps:
// 1) Start application (Platform: Windows Machine)
// 2) Click button that open an additional Window
// 3) Close that new window
// 4) Click button that open an second addition Window
// 5) Close that new window ( Error seen below occurs on closing second window )
Expected behavior
Windows should close without abort the application!
Here is the call stack:
at WinRT.ExceptionHelpers.g__Throw|39_0(Int32 hr)
at ABI.Microsoft.Windows.AppNotifications.IAppNotificationManagerMethods.Unregister(IObjectReference _obj)
at Microsoft.Windows.AppNotifications.AppNotificationManager.Unregister()
at CommunityToolkit.Maui.Options.<>c.b__22_4(Window _, WindowEventArgs _)
at Microsoft.Maui.MauiWinUIWindow.<>c__DisplayClass10_0.b__0(OnClosed del)
at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[TDelegate](IServiceProvider services, Action1 action) at Microsoft.Maui.MauiWinUIWindow.OnClosed(Object sender, WindowEventArgs args) at Microsoft.Maui.MauiWinUIWindow.OnClosedPrivate(Object sender, WindowEventArgs args) at WinRT._EventSource_global__Windows_Foundation_TypedEventHandler_object__global__Microsoft_UI_Xaml_WindowEventArgs_.EventState.<GetEventInvoke>b__1_0(Object sender, WindowEventArgs args) at ABI.Windows.Foundation.TypedEventHandler2.Do_Abi_Invoke[TSenderAbi,TResultAbi](Void* thisPtr, TSenderAbi sender, TResultAbi args)
Screenshots
No response
Code Platform
- UWP
- WinAppSDK / WinUI 3
- Web Assembly (WASM)
- Android
- iOS
- MacOS
- Linux / GTK
Windows Build Number
- Windows 10 1809 (Build 17763)
- Windows 10 1903 (Build 18362)
- Windows 10 1909 (Build 18363)
- Windows 10 2004 (Build 19041)
- Windows 10 20H2 (Build 19042)
- Windows 10 21H1 (Build 19043)
- Windows 10 21H2 (Build 19044)
- Windows 10 22H2 (Build 19045)
- Windows 11 21H2 (Build 22000)
- Other (specify)
Other Windows Build number
Windows 11 10.0.26100 (Build 26100)
App minimum and target SDK version
- Windows 10, version 1809 (Build 17763)
- Windows 10, version 1903 (Build 18362)
- Windows 10, version 1909 (Build 18363)
- Windows 10, version 2004 (Build 19041)
- Windows 10, version 2104 (Build 20348)
- Windows 11, version 22H2 (Build 22000)
- Other (specify)
Other SDK version
10.0.19041.0
Visual Studio Version
2022, Preview
Visual Studio Build Number
Microsoft Visual Studio Community 2022 (ARM 64-bit) - Version 17.12.0 Preview 2.1
Device form factor
Desktop
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item.
### Tasks