当我在 .net maui 中为 C# 开发人员尝试示例时出现此错误。
Message=Package.appxmanifest 文件中需要进行其他设置才能在 Windows 上启用 Snackbar。
此外,必须调用
UseMauiCommunityToolkit(options => options.SetShouldEnableSnackbarOnWindows(true);
才能在 Windows 上启用 Snackbar。有关详细信息,请参阅 Snackbar 文档的平台特定初始化部分:https://learn.microsoft.com/dotnet/communitytoolkit/maui/alerts/snackbar
我访问了该网站,并从 https://learn.microsoft.com/dotnet/communitytoolkit/maui/alerts/snackbar
进行了如下更改这是来自 mauiProgram.cs 的代码
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder().UseMauiCommunityToolkit(options => options.SetShouldEnableSnackbarOnWindows(true));
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.UseMauiCommunityToolkitMarkup()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
package.appxmanifes 文件中所做的更改
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
IgnorableNamespaces="uap rescap desktop">
程序启动然后获取未处理异常的消息。我不知道该去哪里看。试图在网上找到简单的样本。请注意,toast 在网站上有效。
我可以重现您的问题,并通过添加 Jason 所说的步骤来修复它:
在 Package.appxmanifest 中的每个标签内,添加以下扩展:
<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="YOUR-PATH-TO-EXECUTABLE" DisplayName="$targetnametoken$" Arguments="----AppNotificationActivated:"> <!-- Example path to executable: CommunityToolkit.Maui.Sample\CommunityToolkit.Maui.Sample.exe -->
<com:Class Id="6e919706-2634-4d97-a93c-2213b2acc334" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
</Extensions>
我检查了 github repo 中的示例。您的项目的
Executable="YOUR-PATH-TO-EXECUTABLE"
应为 Executable="Your prject name\Your project name.exe"
。在我的项目中,它是Executable="MauiAppTest\MauiAppTest.exe"
并且小吃栏可以正确显示。