1

I am creating a WinRT-flavored Windows Phone 8.1 app. It uses a GridView to show many tiles that users can tap to execute commands. Users can also hold a tile to enter ReorderMode for the GridView. I enable reordering when the user holds a tile by setting ReorderMode. Since each tile contains a button with a command bound to it, I also set IsEnabled = false for the button in each tile. This allows the user to reorder tiles without triggering commands.

My problem is re-enabling the button in each tile when the user exits ReorderMode. By default, a user can tap the back button to exit ReorderMode, but I have not found any event to listen to. Is there an event that fires when ReorderMode is disabled that I can listen for to re-enable the button in each tile? Subscribing to HardwareButtons.BackPressed does not work.

Community
  • 1
  • 1
  • Look at the answer of Jerry Nixon here: http://stackoverflow.com/questions/16388867/xaml-c-what-event-fires-after-reordering-a-gridview I think it explains how this works – Depechie Nov 13 '14 at 10:41
  • Yeah. I read that answer to get started, but it doesn't say anything about an event when leaving reorder mode with the back button. I've hacked around it for now by only allowing the user to reorder one tile at a time and leaving reorder mode after the CollectionChanged event finished its work. – CuriousCurmudgeon Nov 13 '14 at 14:54
  • Maybe that is the only way to do it? It seems a huge short comming in the api though :) – Depechie Nov 13 '14 at 15:03
  • I'm leaning that way myself. I'll leave this open a little longer, but I'll probably end up adding my solution as the answer. – CuriousCurmudgeon Nov 13 '14 at 15:04
  • You will just have to code for it. Is there a ReorderModeChanged event? Is there a PropertyChanged that ReorderMode is part of? Can't you listen for the back button event? – Jerry Nixon Nov 13 '14 at 17:50
  • @CuriousCurmudgeon - check my solution with LostFocus event. It is fired after you stop dragging single item. – Marcin Zablocki Jun 06 '15 at 11:46

2 Answers2

1

Subscribing to the back button doesn't work as the GridView eats that event before you see it. You have to bind to ReorderMode: ReorderMode="{Binding ReorderProperty, Mode=TwoWay}"

Then in the ReorderProperty setter, have code that handles the change.

RandomEngy
  • 14,931
  • 5
  • 70
  • 113
0

I've came across this problem recently and my solution for reordering items with drag and drop with nice user experience was to:

  1. Enable dragging when GridView item is double-tapped:
private void GridView_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            if (sender is GridView)
            {
                (sender as GridView).ReorderMode = ListViewReorderMode.Enabled;
            }
        }
  1. Disable reordering when Grid looses focus:
    private void GridView_LostFocus(object sender, RoutedEventArgs e)
            {
                if (sender is GridView)
                {
                    (sender as GridView).ReorderMode = ListViewReorderMode.Disabled;
                }
            }

My grid view XAML code was:

<GridView  
ItemsSource="{Binding MyObservableCollection}" 
AllowDrop="True"    
CanDragItems="True" 
CanReorderItems="True" 
DoubleTapped="GridView_DoubleTapped" 
LostFocus="GridView_LostFocus" >

Of course it is a solution for Windows Phone 8.1 GridView.

Marcin Zablocki
  • 10,171
  • 1
  • 37
  • 47