2

I am trying to send list of BarData objects to my FavoritesPage.xaml.cs through MessagingCenter. I have tried

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

and it gives me an error, telling me I can't convert the sender from a list to an object. I then tried to use

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

and visual studio screams at me LOL! I tried search online how to send a list of objects through MessagingCenter but I can't find anything. Can someone please help?

1 Answer 1

2

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.

Example

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

Where MainPage is the type of this, and List<BarData> is the argument type

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for answering my question. Would I still put MainPage even though I don't want the list of objects to be sent to the MainPage?
@MirandaHall Its not sending to the main page, its the page or context your are on, so replace MainPage, with where ever you are
How would you set up the Subscribe feature?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.