Good morning,
I added the Command property to a MenuItem but it does not work
The code of the xaml is the following:
<ListView
ItemsSource="{Binding Categorias}"
SelectedItem="{Binding SelectedCategoria, Mode=TwoWay}"
HasUnevenRows="false"
RowHeight="55"
Margin="40,0,25,0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Text="Ver" />
<MenuItem Text="Eliminar"
Command="{Binding EliminarCategoria}" />
</ViewCell.ContextActions>
<templates:CategoriaListItemTemplate/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The code of the ViewModel is as follows:
public CategoriasViewModel(
ICategoriasService categoriaService,
ISqliteService sqliteService,IUserDialogs userDialogService)
{
_categoriaService = categoriaService;
_sqliteService = sqliteService;
_userDialogService = userDialogService;
EliminarCategoria = new Command(ExecuteEliminarCategoria);
}
public Command EliminarCategoria { get; private set; }
private async void ExecuteEliminarCategoria()
{
var categoria = SelectedCategoria;
var sqlCategoria = new Models.Categorias.SqlCategorias
{
idCategoria = categoria.idCategoria,
name = categoria.name,
activated = false
};
await _sqliteService.Insert(sqlCategoria);
_userDialogService.Toast("Categoria eliminada del catálogo.");
}
What can I be doing wrong?
Thank you.