I have a ListView with a custom viewcell where I put a button in.
When I press this button, the listitem should be deleted. Now how do I get the item of the viewcell from within the viewCell?
Or can this task be achieved with a different approach?
Here's what I thought of:
myLV.ItemTemplate=new DataTemplate(typeof(MyCustomCell));
myLV.ItemsSource=myObservableCollection
And here the code of the custom viewcell:
public class MyCustomCell: ViewCell
{
var lblText=new Label();
lblText.SetBinding(Label.TextProperty, new Binding("Infotext");
var btnDelete=new Button{Text="Delete"};
btnDelete.Clicked+=(sender,e)=>{
//how can I reference the current Item and delete it from the collection?
}
var sl=new StackLayout(Orientation=StackOrientation.Horizontal);
sl.Children.add(lblText);
sl.Children.add(btnDelete);
View=sl;
}