简体   繁体   English

在Windows Phone 8.1上退出GridView的重新排序模式时发生的事件

[英]Event when exiting GridView's reorder mode on Windows Phone 8.1

I am creating a WinRT-flavored Windows Phone 8.1 app. 我正在创建WinRT风格的Windows Phone 8.1应用程序。 It uses a GridView to show many tiles that users can tap to execute commands. 它使用GridView来显示用户可以点击以执行命令的许多图块。 Users can also hold a tile to enter ReorderMode for the GridView . 用户还可以按住图块进入GridView ReorderMode I enable reordering when the user holds a tile by setting ReorderMode . 当用户通过设置ReorderMode握住图块时,可以启用重新排序。 Since each tile contains a button with a command bound to it, I also set IsEnabled = false for the button in each tile. 由于每个磁贴包含一个绑定了命令的按钮,因此我还将每个磁贴中的按钮设置为IsEnabled = false 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 . 我的问题是在用户退出ReorderMode时重新启用每个ReorderMode贴中的按钮。 By default, a user can tap the back button to exit ReorderMode , but I have not found any event to listen to. 默认情况下,用户可以点击“后退”按钮退出ReorderMode ,但是我没有找到要监听的事件。 Is there an event that fires when ReorderMode is disabled that I can listen for to re-enable the button in each tile? 禁用ReorderModeReorderMode会触发一个事件,我可以侦听以重新启用每个ReorderMode中的按钮? Subscribing to HardwareButtons.BackPressed does not work. 订阅HardwareButtons.BackPressed不起作用。

Subscribing to the back button doesn't work as the GridView eats that event before you see it. 预订后退按钮不起作用,因为GridView在看到该事件之前就将其吃掉了。 You have to bind to ReorderMode: ReorderMode="{Binding ReorderProperty, Mode=TwoWay}" 您必须绑定到ReorderMode: ReorderMode="{Binding ReorderProperty, Mode=TwoWay}"

Then in the ReorderProperty setter, have code that handles the change. 然后在ReorderProperty设置器中,具有处理更改的代码。

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: 双击GridView项时启用拖动:
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: 当Grid失去焦点时,禁用重新排序:
private void GridView_LostFocus(object sender, RoutedEventArgs e)
            {
                if (sender is GridView)
                {
                    (sender as GridView).ReorderMode = ListViewReorderMode.Disabled;
                }
            }

My grid view XAML code was: 我的网格视图XAML代码是:

<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 . 当然,它是Windows Phone 8.1 GridView的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM