akshay2000
akshay2000

Reputation: 824

Custom SelectionMode for GridView. Select only on right click

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:

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

Answers (1)

chue x
chue x

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

Related Questions