Hi all!
I have some content page with list that has customized cells.
public class HomePage : ContentPage
{
ListView listView = new ListView { ItemTemplate = new DataTemplate(typeof(ProductItemCellView)) };
listView.ItemSelected += async (sender, e) =>
{
var productItem = (ProductItem)e.SelectedItem;
var itemDetailsPage = new ItemDetailsPage(productItem);
await Navigation.PushAsync(itemDetailsPage);
};
}
Cells are customized with additional button in each of them. This button should perform another action differ to the action caused by clicking on the list cell.
public class ProductItemCellView : ViewCell
{
public ProductItemCellView()
{
var layout = new StackLayout
{
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.StartAndExpand,
Children = { CreateButtonLayout() }
};
View = layout;
}
static StackLayout CreateButtonLayout()
{
var descriptionButton = new Button { Text = "+" };
descriptionButton.Clicked += async (sender, e) =>
{
//await DisplayAlert("Alert", "You have been alerted", "OK");
};
var buttonLayout = new StackLayout()
{
HorizontalOptions = LayoutOptions.Center,
Orientation = StackOrientation.Vertical,
Children = { descriptionButton }
};
return buttonLayout;
}
}
The question is - is there a way to catch the event of button click inside of the HomePage class where I initialize the ListView to have another action for this event while leaving the listView.ItemSelected action too?
Thanks!