How to get data from modal window after close?

NazarGrycshuk.2974NazarGrycshuk.2974 USMember, University

Hey Guys )
Could u help me with a problem
i try to open modal window , and when modal window will close get data from ViewModel of that modal window

var editAddressPage = new DeliveryEditAddress();
await Navigation.PushModalAsync(new NavigationPage(editAddressPage));
var context = editAddressPage.BindingContext;

could u give me some tips how i can do that, i think, i can use Messaging center, but it should be better solution

Thanks

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    something of public in "App"?

  • NazarGrycshuk.2974NazarGrycshuk.2974 USMember, University

    Hi Alessandro, thanks for quick response. Yes, but steel i should send a message about the data set, when modal was closed,
    also App is global variable. in this case i can send additional data with message.

  • DavePaulDavePaul CAMember ✭✭

    You could create your view model in the previous class then pass it to the modal window.

        var editAddressModel = new editAddressModel();
        var editAddressPage = new DeliveryEditAddress(editAddressModel);
    
        await  Navigation.PushModalAsync(new NavigationPage(editAddressPage));
    

    then your DeliveryAddressPage is like this

        public class DeliveryEditAddress:ContentPage
        {
                public DeliveryEditAddress(editAddressModel model)
                {
                        this.bindingcontext = model;
                        //page code here
                }
        }
    

    then when you are done the editAddresModel is accessible and populated with your data from the modal window.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    This blog post (and this one) describes techniques for dealing with this kind of issue.

Sign In or Register to comment.