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
CodePudding user response:
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");