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

Bug in ItemSelected Event Handler of ListView

$
0
0

Hi,

I think I found a Bug in ItemSelected Event Handler of a list view. I have the following layout:

        var listView = new ListView()
        {
            ItemsSource = _viewModel.Items,
            ItemTemplate = new DataTemplate(CreateListViewItemTemplate),
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
        };

        listView.ItemSelected += (sender, args) =>
        {
            _viewModel.ItemTapped((IItem) args.SelectedItem);
        };

    private ViewCell CreateListViewItemTemplate()
    {
        var detailsButton = new Button()
        {
            Text = "Details",
            HorizontalOptions = LayoutOptions.End,
        };
        detailsButton.Clicked += (sender, args) =>
        {
            _viewModel.DetailsTapped((IItem)(sender as View).BindingContext);
        };

        itemStackLayout.Children.Add(detailsButton);

        return new ViewCell()
        {
            View = itemStackLayout
        };
    }

Every Item has a button for navigating to a detail page (the actual click on the item should do something other, so this is currently ok).

The problem is: If you click on the button, the event handler for that button is executed, after that the event handler for "ItemSelected" for the listview is executed.

Is this is bug or standard behavior?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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