使用视图模型中的 DisplayActionSheet
using a DisplayActionSheet from viewmodel
我想在我的视图模型中使用 DisplayActionSheet,通过按下按钮调用的命令调用它。问题是我无权访问 DisplayActionSheet(名称 DisplayActionSheet 在当前上下文中不存在)。通常我会把它放在 page.xaml.cs 文件中,但问题是每次执行某个操作时我都试图删除标签,并且标签集合位于视图模型中。我希望你理解我的问题。
<ImageButton
Source="Kurv.png"
Command="{Binding Path=BindingContext.RemoveOrdreCommand, Source={x:Reference OrdreListe}}"
CommandParameter="{Binding .}"
/>
和
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);
}
}
** 是给我错误的地方。
如果我尝试将它作为事件处理程序放在 page.xaml.cs 中,我将无法访问我可观察到的 OrdreItems 集合
DisplayActionSheet
是Page
的一个方法。要从您的虚拟机访问它,您可以这样做
App.Current.MainPage.DisplayActionSheet("Vil du tage imod denne ordre?", "Annullér", null, "Ja", "Nej");
我想在我的视图模型中使用 DisplayActionSheet,通过按下按钮调用的命令调用它。问题是我无权访问 DisplayActionSheet(名称 DisplayActionSheet 在当前上下文中不存在)。通常我会把它放在 page.xaml.cs 文件中,但问题是每次执行某个操作时我都试图删除标签,并且标签集合位于视图模型中。我希望你理解我的问题。
<ImageButton
Source="Kurv.png"
Command="{Binding Path=BindingContext.RemoveOrdreCommand, Source={x:Reference OrdreListe}}"
CommandParameter="{Binding .}"
/>
和
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);
}
}
** 是给我错误的地方。 如果我尝试将它作为事件处理程序放在 page.xaml.cs 中,我将无法访问我可观察到的 OrdreItems 集合
DisplayActionSheet
是Page
的一个方法。要从您的虚拟机访问它,您可以这样做
App.Current.MainPage.DisplayActionSheet("Vil du tage imod denne ordre?", "Annullér", null, "Ja", "Nej");