c# - 更改 MAUI Blazor 混合应用程序中的 Windows 托盘图标 - 找不到 OnNativeMessage 定义

标签 c# blazor hybrid maui maui-blazor

我最近一直在学习 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/

相关文章:

c# - 在 PostBack 之后保持 gridview 中 div 的滚动条位置

c# - 从单用户桌面应用程序转向多用户开发

c# - 当组件加载 html/css 时 blazor 加载微调器

c# - 机器人框架 .Net 中的本地化

.net - 在同一个项目中结合 MVC + Blazor

blazor - 如何将字符串参数传递给 Blazor 中的 @onclick 事件?

azure - 无法使用 Azure 混合连接连接到 SQL Server Analysis Services

javascript - ThreeJS 应用程序在 XDK 模拟器中运行良好,但在真实设备上运行不佳

javascript - 在 ionic 2/3 中获取相同模态的多个实例

c# - Saxon 9 Compiled Transform 的线程安全