Skip to content

DataGrid Cancel Edit Crashes with a template column binding to Run.Text #8816

@kmzeise

Description

@kmzeise

Description

In a data grid setup with

<DataGridTemplateColumn Header="Crash" IsReadOnly="True">
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <TextBlock>
        <Run Text="{Binding SomeValue}" />
      </TextBlock>
    </DataTemplate>
</DataGridTemplateColumn>

This crashes when I edit the text column and then cancel it with ESC.

The Exception is thrown in VisualTreeUtils.EnsureVisual, with text '{0}' is not a Visual or Visual3D.

Reproduction Steps

Create a WPF application for .NET Framework 4.8
Put a Datagrid on the window, and add the template column shown above

Expected behavior

Does not throw an exception

Actual behavior

Throws an exception

Regression?

No response

Known Workarounds

If you add to the binding a Mode=OneWay specification, the crash does not occur

Impact

Need to find the workaround and apply it in code, adding unnecessary complexity.

Configuration

Windows 10, fully updated February 2023, .NET Framework 4.8.1

Other information

When restoring information, the code seems to go through the bindings, and assumes that all are bound to a Visual. But a Run is not a visual.

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvestigateRequires further investigation by the WPF team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions