Skip to content

Implicit x:DataType is ignored, if InheritDataTypeFromItems.AncestorType doesn't have an exact match #18192

Closed
@maxkatz6

Description

@maxkatz6

x:DataType is implicitly assumed from the DataGrid.ItemsSource thanks to this attribute defined on the base column class: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls.DataGrid/DataGridBoundColumn.cs#L28

It seems compiled doesn't respect AncestorType-delivered types and only expects exact match.
As a workaround, I would recommend explicitly setting x:DataType on these columns.

This specific line should be replaced

.FirstOrDefault(n => n.Type.GetClrType().FullName == xamlType.FullName);

-     .FirstOrDefault(n => n.Type.GetClrType().FullName == xamlType.FullName);
+     .FirstOrDefault(n => xamlType.IsAssignableFrom(n.Type.GetClrType()));

If anybody can make a quick change and simple unit test, it will be really helpful.

Originally posted by @maxkatz6 in #18186 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions