w-ahmad/WinUI.TableView

Add RightMouseClick in cell

Closed this issue · 1 comments

I need that in order to display further information on a clicked cell.
Makes it also possible to have a cell-based contextmenu, or something like a hyperlink.

Implementation should be not so complicated:

  1. create new Eventargs:
public class TableViewCellRightTapEventArgs : HandledEventArgs
{
    public TableViewCellRightTapEventArgs(int row, int col, object dataContext)
    {
        Row = row;
        Column = col;
        DataContext = dataContext;
    }

    public int Row { get; }
    public int Column { get; }
    public object DataContext{ get; }
}

with row/column obvious, DataContext showing the whole item from ItemsCollection[row].

  1. in TableView add a new Event + Handler:
    public event EventHandler<TableViewCellRightTapEventArgs>? CellRightTap;
    internal void OnCellRightTap(TableViewCellRightTapEventArgs args)
    {
        CellRightTap?.Invoke(this, args);
    }
  1. in TableViewCell add:
    protected override void OnRightTapped(RightTappedRoutedEventArgs e)
    {
        base.OnRightTapped(e);
        var args = new TableViewCellRightTapEventArgs(Slot.Row, Slot.Column, DataContext);

        TableView.OnCellRightTap(args);
    }

Then in Xaml you can say:

            <table:TableView x:Name="tableView1"
                             CellRightTap="tableView1_CellRightTap" ... />

I also thought about including Content from the cell. But I feel that might publish information about the internal realisation (eg. TextBox/CheckBox/...) which should be probably hidden.

Thank you, @VisualAlf, for your suggestions. I appreciate that you've highlighted a feature that could enhance the control's customizability.