Add RightMouseClick in cell
Closed this issue · 1 comments
VisualAlf commented
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:
- 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].
- in TableView add a new Event + Handler:
public event EventHandler<TableViewCellRightTapEventArgs>? CellRightTap;
internal void OnCellRightTap(TableViewCellRightTapEventArgs args)
{
CellRightTap?.Invoke(this, args);
}
- 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.
w-ahmad commented
Thank you, @VisualAlf, for your suggestions. I appreciate that you've highlighted a feature that could enhance the control's customizability.