如何在 C# 中通过 MessagingCenter 发送对象列表?

How do I send a list of objects through MessagingCenter in C#?

我正在尝试通过 MessagingCenter 将 BarData 个对象列表发送到我的 FavoritesPage.xaml.cs。我试过了

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

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

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

和 visual studio 对着我尖叫,哈哈! 我尝试在线搜索如何通过 MessagingCenter 发送对象列表,但我找不到任何内容。有人可以帮忙吗?

MessagingCenter.Send Method

Sends a named message with the specified arguments

Parameters

  • sender TSender

    • The instance that is sending the message. Typically, this is specified with the this keyword used within the sending object.
  • message String

    • The message that will be sent to objects that are listening for the message from instances of type TSender.
  • args TArgs

    • The arguments that will be passed to the listener's callback.

例子

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

其中MainPagethis的类型,List<BarData>是参数类型