Skip to main content
A newer version of this page is available. .

DXCollectionView.TapCommand Property

Gets or sets the command executed when a user taps the DXCollectionView. This is a bindable property.

Namespace: DevExpress.Maui.CollectionView

Assembly: DevExpress.Maui.CollectionView.dll

NuGet Package: DevExpress.Maui.CollectionView

Declaration

public ICommand TapCommand { get; set; }

Property Value

Type Description
ICommand

A command that exposes the ICommand interface.

Remarks

The TapCommand‘s CommandParameter property is hidden and its value is internally set to the ItemsSource‘s object used to create the tapped CollectionView item. You can access the item in the command if you define the command with a parameter.

You can also use the following commands to respond to different gesture types:

For more information about using commands in MAUI, refer to the following page: Commanding.

Example

The following example shows a message when a user taps a collection view item:

<ContentPage.BindingContext>
    <local:ViewModel/>
</ContentPage.BindingContext>
<dxcv:DXCollectionView ItemsSource="{Binding Data}" 
                       DisplayMember="Name"
                       TapCommand="{Binding TapItemCommand}">
    <!--...-->
</dxcv:DXCollectionView>
using Microsoft.Maui.Controls;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

namespace CollectionViewExample {
    public class ViewModel : INotifyPropertyChanged {
        public ICommand TapItemCommand { get; set; }
        public List<Contact> Data { get; }
        public ViewModel() {
            Data = new List<Contact>() {
                new Contact("Nancy Davolio", "(206) 555-9857"),
                // ...
            };
            this.TapItemCommand = new Command<Contact>(OnItemTap);
        }
        private void OnItemTap(Contact contact) {
            string contactName = contact.Name;
            string contactPhone = contact.Phone;
            Application.Current.MainPage.DisplayAlert("Contact Info", "Name: " + contactName + "\n" + "Phone: " + contactPhone, "OK");
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public class Contact {
        string name;
        public string Name {
            get => this.name;
            set {
                this.name = value;
                if (Photo == null) {
                    string resourceName = value.Replace(" ", "").ToLower() + ".jpg";
                    Photo = ImageSource.FromFile(resourceName);
                }
            }
        }

        public Contact(string name, string phone) {
            Name = name;
            Phone = phone;
        }
        public ImageSource Photo { get; set; }
        public string Phone { get; set; }
    }
}
See Also