首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过MessagingCenter在C#中发送对象列表?

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

Stack Overflow用户
提问于 2021-09-22 07:25:38
回答 1查看 345关注 0票数 1

我正试图通过BarDataFavoritesPage.xaml.cs对象的列表发送到FavoritesPage.xaml.cs。我试过了

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

它给了我一个错误,告诉我我不能把发送者从一个列表转换成一个对象。然后我试着用

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-22 07:55:09

MessagingCenter.Send法

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

  • 发送方TSender
代码语言:javascript
复制
- The instance that is sending the message. Typically, this is specified with the this keyword used within the sending object.
  • 消息String
代码语言:javascript
复制
- The message that will be sent to objects that are listening for the message from instances of type TSender.
  • args TArgs
代码语言:javascript
复制
- The arguments that will be passed to the listener's callback.

示例

代码语言:javascript
复制
MessagingCenter.Send<MainPage,List<BarData>>(
    this, // the context you are on 
    "FaveBars", // the named message
    _favoriteBarsList); // the argument

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69279872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档