简体   繁体   English

如何在Win10的新Outlook应用程序中实现滑动手势?

[英]How to implement the swipe gesture as in new Outlook app for Win10?

新的Outlook应用程序

The new Outlook app for Windows 10 implements swipe gesture to delete or edit Items.I want to implement this functionality for Listview items in my universal app using C# and XAML. Windows 10的新Outlook应用程序实现了滑动手势以删除或编辑项目。我想使用C#和XAML在通用应用程序中为Listview项目实现此功能。

So far I am trying the following approach : 到目前为止,我正在尝试以下方法:

XAML XAML

                <Grid Name="EditTestGrid" Height="50" Width="100" HorizontalAlignment="Right">
                    <Grid Name="EditGrid" Background="Black" Height="50" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                    </Grid>
                </Grid>

            </Grid>

            <Grid Name="DataGrid" Visibility="Visible" Background="GhostWhite">
                <Grid.RenderTransform>
                    <TranslateTransform x:Name="TranslateGrid"
                                        X="0"/>
                </Grid.RenderTransform>
                <Grid>
                    <Path Data="{Binding Art}" 
                          Stretch="Uniform" Fill="{Binding Colour}" 
                          Width="26" Height="26" 
                          HorizontalAlignment="Center"
                          Opacity="0.5"/>
                    <Rectangle Height="30" 
                               Width="3"
                               HorizontalAlignment="Right"
                               Fill="Teal"/>
                </Grid>
            </Grid>


        </Grid>
    </DataTemplate>
</ListView.ItemTemplate>

C# C#

private void TestList_ManipulationCompleted(object sender,ManipulationCompletedRoutedEventArgs e)
{
  Grid dataGrid = findElementInItemsControlItemAtIndex(TransactionList, TransactionList.SelectedIndex, "DataGrid") as Grid;

  if (dataGrid != null)
  {
    TranslateTransform myTranslate = new TranslateTransform();
    double dist = e.Cumulative.Translation.X;
    if (dist < -80)
    {
        myTranslate.X = -100;
        dataGrid.RenderTransform = myTranslate;
    }

    if (dist > 40)
    {
        myTranslate.X = 0;
        dataGrid.RenderTransform = myTranslate;
    }

  }
}

private void TestList_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
  Grid dataGrid = findElementInItemsControlItemAtIndex(TransactionList, TransactionList.SelectedIndex, "DataGrid") as Grid;

if (dataGrid != null)
{
    TranslateTransform myTranslate = new TranslateTransform();
    double dist = e.Cumulative.Translation.X;
    var manipulation = e.Delta;
    myTranslate.X += manipulation.Translation.X;
    dataGrid.RenderTransform = myTranslate;
    if (dist < -40)
    {
        myTranslate.X = -100;
        dataGrid.RenderTransform = myTranslate;
    }

    if (dist > 70)
    {
        myTranslate.X = 0;
        dataGrid.RenderTransform = myTranslate;

    }
}

} }

This approach works only when user selects an item in listview and then swipes to left or right.The findElementInItemsControlItemAtIndex() method returns only the selected control and not the control on which manipulation is happening. 仅当用户在列表视图中选择一个项目然后向左或向右滑动时,此方法才有效。findElementInItemsControlItemAtIndex()方法仅返回所选控件,而不返回对其进行操作的控件。

So is there any way to select an item as soon as manipulation starts on an item ? 那么,一旦对一个项目开始操纵,有什么方法可以选择一个项目吗? Also is there any library for implementing swipe to edit or delete in listview ? 是否有任何库可以实现在列表视图中滑动以进行编辑或删除?

Using UIElement. 使用UIElement。 PointerPressed 指针按下

private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    var ptr = e.Pointer;
    if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        var ptrPt = e.GetCurrentPoint(Target);
    }
    e.Handled = true;
}

More on PointerRoutedEventArgs . 有关PointerRoutedEventArgs的更多信息

Pointer events are intended for scenarios where you're interested in multiple pointers and their relationships, or when you are examining specifics of each pointer such as exact coordinate position. 指针事件适用于您对多个指针及其关系感兴趣,或者正在检查每个指针的详细信息(例如确切的坐标位置)的情况。

Once you have used GetCurrentPoint , you can coordinate where the user is pointing and what is on the screen at that position.To accomplish this, you would use FindElementsInHostCoordinates in the VisualTreeHelper. 使用GetCurrentPoint后 ,可以协调用户指向的位置以及该位置屏幕上的内容。要实现此目的,可以在VisualTreeHelper中使用FindElementsInHostCoordinates

Okay, I think you have all the pieces you need to figure it out. 好的,我认为您已经掌握了所有需要解决的问题。

Best of luck! 祝你好运!

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

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