1

我正在尝试通过 MessagingCenterBarData向我发送对象列表。FavoritesPage.xaml.cs我试过了

MessagingCenter.Send<BarData>(_favoriteBarsList, "FaveBars");

它给了我一个错误,告诉我我无法将发件人从列表转换为对象。然后我尝试使用

MessagingCenter.Send<List<BarData>>(_favoriteBarsList, "FaveBars");

和视觉工作室对我尖叫哈哈!我尝试在线搜索如何通过 MessagingCenter 发送对象列表,但我找不到任何东西。有人可以帮忙吗?

4

1 回答 1

1

MessagingCenter.Send 方法

发送带有指定参数的命名消息

参数

  • 发件人TSender

    • 发送消息的实例。通常,这是使用发送对象中使用的 this 关键字指定的。
  • 信息String

    • 将发送到正在侦听来自 TSender 类型实例的消息的对象的消息。
  • 参数TArgs

    • 将传递给侦听器回调的参数。

例子

MessagingCenter.Send<MainPage,List<BarData>>(
    this, // the context you are on 
    "FaveBars", // the named message
    _favoriteBarsList); // the argument

MainPage的类型在哪里this,并且List<BarData>是参数类型

于 2021-09-22T07:55:09.700 回答