Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessagingCenter.Subscribe callback is not fired on PageModel #295

Open
lucastien opened this issue Nov 8, 2019 · 1 comment
Open

MessagingCenter.Subscribe callback is not fired on PageModel #295

lucastien opened this issue Nov 8, 2019 · 1 comment

Comments

@lucastien
Copy link

I am trying to make a shopping app using FreshMVVM.
I created two pages HomePage and BasketPage (the pagemodels are HomePageModel and BasketPageModel respectively).
HomePage will defined a listview of items and each item will have a button Order. When user clicks Order on a certain item then it will bind to command AddToBasketCommand in the pagemodel.
The command will Send a message (using MessingCenter) with parameter is the item orderred. The code to initialize the command in HomePageModel constructor like this

AddToBasketCommand = new Command<FoodItem>(async (FoodItemfood) =>
{
       await Task.Delay(10);
       MessagingCenter.Send(this, MessageKeys.AddFood, food);
});

On BasketPageModel, I subscribed the message in Init function

public class CartPageModel : FreshBasePageModel
{
       ...
      public override void Init(object initData)
      {
            MessagingCenter.Unsubscribe<HomePageModel, Menu_Tbl>(this, MessageKeys.AddFood);
            MessagingCenter.Subscribe<HomePageModel, Menu_Tbl>(this, MessageKeys.AddFood, async (sender, arg) =>
            {
                Console.WriteLine("Callback for AddToBasketCommand was fired");
                //do some stuffs
            }
       }

When I run the app and click on Order button, the command was binded sucessfully but the callback on MessagingCenter.Subscribe on BasketPageModel is not triggerred.
Can anyone help me on this bug. Thanks

@LeoJHarris
Copy link

@lucastien as a work around can you get the subscribed callback to be invoked in the page of the page view model and then using the binding context do what you need on the view model?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants