我最近一直在学习 MAUI Blazor,想尝试更改窗口左上角的托盘图标,因为它默认为空白。
我一直在学习本教程:
https://www.youtube.com/watch?v=n_HJcDHuMMw
以下面的 repo 为例:
https://github.com/coding-flamingo/BazorAndMaui
但这给我留下了最后一个问题,即使我尝试在 GitHub 上编译示例代码,我也会遇到这个问题:我在 Visual Studio 中收到一个错误,指出“IWindowsLifecycleBuilder”不包含使用的“OnNativeMessage”的定义在以下代码位中:
builder.ConfigureLifecycleEvents(lifecycle =>
{
#if WINDOWS
lifecycle
.AddWindows(windows =>
windows.OnNativeMessage((app, args) => {
if (VTix.Platforms.Windows.WindowExtensions.Hwnd == IntPtr.Zero)
{
VTix.Platforms.Windows.WindowExtensions.Hwnd = args.Hwnd;
VTix.Platforms.Windows.WindowExtensions.SetIcon("Platforms/Windows/trayicon.ico");
}
app.ExtendsContentIntoTitleBar = false;
}));
#endif
});
据我所知,我正在使用所有正确的“using”指令和 nuget 包,所以我不明白为什么找不到该方法。
这是所有“使用”指令:
共享:
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using VTix
@using VTix.Shared
@using Radzen
@using Radzen.Blazor
在 MauiProgram.cs 中:
using VTix.Data;
using VTix.Services;
using Microsoft.AspNetCore.Components.WebView.Maui;
using Microsoft.Maui.LifecycleEvents;
最佳答案
事实证明,.OnNativeMessage
在 2022 年 3 月之后的某个地方(如检查 Wayback Machine 中的 https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/app-lifecycle 所示)重命名为 .OnPlatformMessage
,因此在此之前创建的所有项目都将必须更换它。
关于c# - 更改 MAUI Blazor 混合应用程序中的 Windows 托盘图标 - 找不到 OnNativeMessage 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72816883/