Reputation: 824
I'm trying to implement a bit complicated selection behavior for GridView in my Windows 8 app. I know that it is be possible as OneNote app from Windows Store implements exact same behavior as I want. Here is the behavior I want:
SelectionMode="None"
. Same behavior is expected when an item is tapped on a touchscreen device.SelectionMode="Multiple"
. Similar thing should happen when user selects an item by swiping and pulling it a bit. If I left click an item again, all selected items should be unselected and ItemTapped should trigger.In short, left click and item tap should behave as SelectionMode="None"
while right click and swipe selection should work as SelectionMode="Multiple"
.
Upvotes: 1
Views: 3526
Reputation: 18803
I think you can achieve what you want by first enabling multiple selection, as well as enabling the swipe gesture. Then on left click (in the tapped handler), you can de-select all items in code.
Xaml GridView options - this allows right-click and touch (swipe) selection:
SelectionMode="Multiple"
IsSwipeEnabled="True"
Tapped="itemGridView_Tapped"
Here is the code behind for the tapped event - on a left-click or tap, this deselects any selected items:
private void itemGridView_Tapped(object sender, TappedRoutedEventArgs e)
{
while (itemGridView.SelectedItems.Count > 0)
itemGridView.SelectedItems.RemoveAt(0);
}
Upvotes: 3