Skip to content

DataGrid exception only using Touch when beginning Cell Edit #4893

Open
@ibseanb

Description

@ibseanb

Describe the bug

Using a mouse does not produce this behavior, but only using a touch on a touchscreen or VS simulator. We use the BeginEdit / Cancel Edit functionality of the DataGrid to show the first 3 lines of a block of text, but when tapped, expand it to a larger text view. I've removed all custom functionality and styles but continue to see this every time I touch into a DataGrid cell and call BeginEdit on the control. I've found that this only happens when the touch point actually hits the text block (not the grid view cell itself), and the text block has IsTextSelectionEnabled = true .

Unhandled exception at 0x00007FFDDF42C3FE (Windows.UI.Xaml.dll) in MyApp.exe: 0xC0000005: Access violation writing location 0x0000000000000034.

Regression

No response

Reproducible in sample app?

  • This bug can be reproduced in the sample app.

Steps to reproduce

<Page
    x:Class="UWPApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UWPApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:winui="using:Microsoft.Toolkit.Uwp.UI.Controls"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <winui:DataGrid Grid.Row="1"
        x:Name="LogMessagesGrid"
        CanUserReorderColumns="False"
        CanUserSortColumns="True"
        HeadersVisibility="Column"
        AutoGenerateColumns="False"
        SelectionChanged="LogMessagesGrid_SelectionChanged"
        GridLinesVisibility="All" >
            <winui:DataGrid.Columns>
                <winui:DataGridTemplateColumn MinWidth="200"
                                              Width="*"
                                              Header="Log / Message">
                    <winui:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"
                                       MaxLines="3"
                                       MinHeight="45"
                                       TextWrapping="Wrap"
                                       IsTextSelectionEnabled="True"
                                       HorizontalAlignment="Stretch"
                                       VerticalAlignment="Top"
                                       Margin="10,0" />
                        </DataTemplate>
                    </winui:DataGridTemplateColumn.CellTemplate>

                    <winui:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <Grid  Tapped="LogMessage_Tapped" Background="Green" Height="300">

                                <ScrollViewer Grid.Row="1">
                                    <TextBlock Text="{Binding}"
                                                IsTextSelectionEnabled="True"
                                                HorizontalAlignment="Stretch"
                                               TextWrapping="Wrap"
                                                VerticalAlignment="Top"
                                                Margin="10,0"/>
                                </ScrollViewer>
                            </Grid>
                        </DataTemplate>
                    </winui:DataGridTemplateColumn.CellEditingTemplate>
                </winui:DataGridTemplateColumn>
            </winui:DataGrid.Columns>
        </winui:DataGrid>

    </Grid>
</Page>



using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace UWPApp
{

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            InitializeComponent();

            LogMessagesGrid.ItemsSource = new List<string>()
            {
                "Loren ipsun dolor sit anet, consectetur adipisci elit, sed eiusnod tenpor incidunt ut labore et dolore nagna aliqua. Ut enin ad ninin venian, quis nostrun exercitationen ullan corporis suscipit laboriosan, nisi ut aliquid ex ea connodi consequatur. Quis aute iure reprehenderit in voluptate velit esse cillun dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt nollit anin id est laborun. ips dolor sit amet, consectetur adipisci elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur. Quis aute iure reprehenderit in voluptate velit esse cill dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est labor."
            };
        }

        private void LogMessagesGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0) return;

            if (LogMessagesGrid != null) LogMessagesGrid.BeginEdit();
        }

        private void LogMessage_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (LogMessagesGrid != null)
            {
                LogMessagesGrid.CancelEdit();
                LogMessagesGrid.SelectedIndex = -1;
            }
        }
    }
}

Expected behavior

This is mocked up behavior, but in this example, the grid should show a white background, and when tapped, turn green. When tapped again, go back to white. Using a touch device, tap on the text when it's in the white background mode. It will crash

Screenshots

No response

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)
  • Windows 11 21H2 (Build 22000)
  • Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • 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

2019, 2022

Visual Studio Build Number

No response

Device form factor

Desktop

Nuget packages

No response

Additional context

No response

Help us help you

Yes, but only if others can assist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DataGrid 🔠Issues on DataGrid controlbug 🐛An unexpected issue that highlights incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions