xamarin 当前上下文中不存在名称“MessagingCenter”

qf9go6mv  于 2023-01-06  发布在  其他
关注(0)|答案(2)|浏览(164)

在Xamarin.Forms中,我使用了MessagingCenter,但现在从Xamarin.Forms迁移到Microsoft.Maui.Essentials后,我得到了这个错误:
当前上下文中不存在名称"MessagingCenter"
在我的视图控制器. 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();
}

在Game1.cs中:

MessagingCenter.Send<Game1>(this, "Hi");

MessagingCenter是否仍然可以与Microsoft. Maui一起使用?

    • 编辑:**现在可以用了。我用微软。毛伊岛。控件添加的;然后我就不会再看到错误了。
xggvc2p6

xggvc2p61#

docs
消息中心在. NET 7中已弃用,并由CommunityToolkit. Mvvm NuGet包中的WeakReferenceMessenger替换。有关详细信息,请参阅Messenger。

liwlm1x9

liwlm1x92#

我用的是TargetFramework net6.0-ios。我用的是微软加的。毛伊岛控件;在MyViewController.cs和Game1.cs中,然后我不再收到错误。

相关问题