I've been learning MAUI Blazor lately and wanted to try and change the tray icon in the upper left of the window because it defaults to being blank.
I've been following this tutorial:
https://www.youtube.com/watch?v=n_HJcDHuMMw
Which uses the following repo as an example:
https://github.com/coding-flamingo/BazorAndMaui
but it leaves me with one last issue which I run into even if I try to compile the sample code on GitHub: I get an error in Visual Studio that says that "IWindowsLifecycleBuilder" does not contain a definition for "OnNativeMessage" used in the following code bit:
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
});
From what I can tell I'm using all the correct "using" directives and nuget packages, so I don't understand why the method can't be found.
Here's all the "using" directives:
Shared:
@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
In the MauiProgram.cs:
using VTix.Data;
using VTix.Services;
using Microsoft.AspNetCore.Components.WebView.Maui;
using Microsoft.Maui.LifecycleEvents;
CodePudding user response:
Turnes out .OnNativeMessage
was renamed somewhere after March 2022 (as indicated by checking Wayback Machine for https://docs.microsoft.com/en-us/dotnet/maui/fundamentals/app-lifecycle) to .OnPlatformMessage
, so all projects created before that will have to replace it.
CodePudding user response:
As defauleUserNameN correctly commented: OnNativeMessage
has to be replaced with OnPlatformMessage
, it appears it was renamed.