3

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;
Rand Random
  • 7,300
  • 10
  • 40
  • 88
Fabs
  • 95
  • 7
  • 1
    The App doesn't compile because of the error. I have it set to a Windows machine. I put a link in the OP for a github repository with example code. I can't compile that one either because of the same error. It's the MauiApp1 in this folder in case it's confusing: https://github.com/coding-flamingo/BazorAndMaui/tree/main/BlazorApp1 and there's a .csproj file in there as well. Edit: The comment I replied to was removed, but I'll leave this here for clarification. – Fabs Jun 30 '22 at 14:02
  • 1
    Sorry, I just noticed you had a compiler directive already in the code, so the target shouldn't matter. But thank you for the link. – defaultUsernameN Jun 30 '22 at 14:05
  • 2
    Another thing - would replacing ```OnNativeMessage``` with ```OnPlatformMessage``` work? It seems to do the same thing, maybe it was renamed. (https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/app-lifecycle) – defaultUsernameN Jun 30 '22 at 14:06
  • 1
    Thank you, that was indeed the case! Now it's showing the wrong icon, but I'll be able to figure that one out. – Fabs Jun 30 '22 at 14:15

1 Answers1

3

Turns out .OnNativeMessage was renamed somewhere after March 2022 (as indicated by checking Wayback Machine for https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/app-lifecycle) to .OnPlatformMessage, so all projects created before that will have to replace it.

defaultUsernameN
  • 365
  • 5
  • 14