I have a GridView like below
You should set SelectionMode="Single"in gridview and set IsRightTapEnabled="True".
My model has a class Student:
public class Student : NotifyProperty
{
public string Name
{
set
{
_name = value;
OnPropertyChanged();
}
get
{
return _name;
}
}
private string _name;
}
And my viewmodel has a List.
I set the list as gridview's source.
My gridview is
The SymbolGridView_OnRightTapped have a OriginalSource that is TextBlock.But if your DataTemlpate is a Grid ,the OriginalSource is Grid.
We can use var student = (e.OriginalSource as TextBlock)?.DataContext as Student; to get the student.
The OriginalSource.DataContext is your selects item
But if you use the Grid,the OriginalSource may is ListViewItemPresenter.So the easy methor is use var student = (e.OriginalSource as FrameworkElement)?.DataContext as Student;
See: http://lindexi.oschina.io/lindexi/post/win10-uwp-%E5%8F%B3%E5%87%BB%E9%80%89%E6%8B%A9GridViewItem