Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to get the item of a ListView's ViewCell?

$
0
0

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;
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>