Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

using a DisplayActionSheet from viewmodel

I want to use a DisplayActionSheet inside my viewmodel, that gets called via a command that gets called by the press of a button. the problem is i dont have access to DisplayActionSheet (the name DisplayActionSheet doesnt exist in current context). Normally i would have just put it in the page.xaml.cs file but the problem is that i am trying to remove a label everytime a certain action is taken, and the collection of labels is located inside the viewmodel. i hope you understand my question.

<ImageButton 
                                Source="Kurv.png"
                                Command="{Binding Path=BindingContext.RemoveOrdreCommand, Source={x:Reference OrdreListe}}"
                                CommandParameter="{Binding .}"
                                
                            />

and

public ICommand RemoveOrdreCommand => new Command(RemoveOrdreItem);
    public async void RemoveOrdreItem(object o)
    {
        string svar = await *DisplayActionSheet*("Vil du tage imod denne ordre?", "Annullér", null, "Ja", "Nej");
        OrdreItem ordreItemBeingRemoved = o as OrdreItem;
        if (svar == "Ja")
        {
            OrdreItems.Remove(ordreItemBeingRemoved); 
        }

    }

the ** is where it gives me the error.
if i try putting it as an eventhandler in the page.xaml.cs i cant access my observable collection of OrdreItems

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

DisplayActionSheet is a method of Page. To access it from your VM, you can do this

App.Current.MainPage.DisplayActionSheet("Vil du tage imod denne ordre?", "Annullér", null, "Ja", "Nej");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading