Reputation: 133
In Xamarin.Forms I used MessagingCenter but now after migrating from Xamarin.Forms to Microsoft.Maui.Essentials I get this error:
The name 'MessagingCenter' does not exist in the current context
In MyViewController.cs:
MessagingCenter.Subscribe<Game1>(this, "Hi", (sender) =>
{
G_RemoveLogoTestMyView();
});
public void G_RemoveLogoTestMyView()
{
//remove image
var LogoView = View.ViewWithTag(1234);
if (null != LogoView)
LogoView.RemoveFromSuperview();
}
And in Game1.cs:
MessagingCenter.Send<Game1>(this, "Hi");
Is it still possible to use MessagingCenter with Microsoft.Maui?
EDIT: It works now. I added using Microsoft.Maui.Controls; and then I don't get the error anymore.
Upvotes: 0
Views: 828
Reputation: 133
I use TargetFramework net6.0-ios. I added the namespace using Microsoft.Maui.Controls; in MyViewController.cs and in Game1.cs and then I don't get the error anymore.
Upvotes: 0