WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

DataGrid Sorting by Tap does not always fire

Open TorstenKannler opened this issue 8 months ago • 1 comments

Describe the bug

A tap on the column header rarely triggers a dataGrid sorting event. When you click with the mouse on column header, the event is always triggered immediately, as expected.

Regression

No response

Reproducible in sample app?

  • [ ] This bug can be reproduced in the sample app.

Steps to reproduce

To reproduce:

1. Use Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
2. Set DataGrid requirements -> DataGrid.CanUserSortColumns and DataGridColumn.CanUserSort both to true
3. Handle the Sorting event and write a debug message to output window
4. Start the app on a device with a touch screen (e.g. a Surface)
5. Use mouse click on the column headers to get sorting events -> works fine
6. Use tap on the column headers to get sorting event -> only every 2nd or 3rd event will be raised.
   Also change tap between the columns.


I reproduced the behavior in a small UWP App, here is the code:

<!-- MainPage.xaml -->
<Page
    x:Class="DataGridSortingTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DataGridSortingTest"
    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid>
        <controls:DataGrid  
            x:Name="dataGrid"
            IsTapEnabled="True"
            VerticalAlignment="Stretch" 
            HorizontalAlignment="Stretch"
            HorizontalScrollBarVisibility="Visible"
            VerticalScrollBarVisibility="Visible"
            AreRowDetailsFrozen="True"
            AreRowGroupHeadersFrozen="True"
            AutoGenerateColumns="False"
            CanUserReorderColumns="False"
            CanUserResizeColumns="False"
            ColumnHeaderHeight="80"
            GridLinesVisibility="None"
            HeadersVisibility="Column"
            IsReadOnly="True"
            SelectionMode="Single"
            RowHeight="40"     
            RowDetailsVisibilityMode="Collapsed"

            CanUserSortColumns="True"
            Sorting="dataGrid_Sorting">
            
            <controls:DataGrid.Columns>
                <controls:DataGridTextColumn Header="COL1"
                                                     CanUserSort="True"
                                                     SortDirection="{x:Null}"
                                                     Tag="COL1"
                                                     />
                <controls:DataGridTextColumn Header="COL2"
                                                     CanUserSort="True"
                                                     SortDirection="{x:Null}"
                                                     Tag="COL2"
                                                     />
            </controls:DataGrid.Columns>
        </controls:DataGrid>

    </Grid>
</Page>

// MainPage.xaml.cs
private void dataGrid_Sorting(object sender, Microsoft.Toolkit.Uwp.UI.Controls.DataGridColumnEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Sort: " + e.Column.Tag.ToString());
}

Expected behavior

The tap action on column header should trigger a sorting event for each tab, just like clicking with the mouse.

Screenshots

By mouse click 5xCOL1 and 5xCOL2

ScreenshotByMouseClick

By tap 5xCOL1 and 5xCOL2

ScreenshotByTap

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [ ] Windows 10 21H1 (Build 19043)
  • [X] Windows 11 21H2 (Build 22000)
  • [ ] Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • [X] Windows 10, version 1809 (Build 17763)
  • [ ] Windows 10, version 1903 (Build 18362)
  • [ ] Windows 10, version 1909 (Build 18363)
  • [ ] Windows 10, version 2004 (Build 19041)
  • [ ] Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

17.6.6

Device form factor

Desktop

Nuget packages

Microsoft.Toolkit.Uwp.UI.Controls 7.1.3

Including the transitive packages: Microsoft.Toolkit.Uwp.UI.Controls.DataGrid 7.1.3

Additional context

No response

Help us help you

No.

TorstenKannler avatar Oct 10 '23 11:10 TorstenKannler