[Bug]: XAML Previewer sample data for CollectionViewSource with ItemsPath ignores generated rows when item properties have C# initializers

Abierto Apto para principiantes
#344 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 15 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
80/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp
Área
tooling

Línea de trabajo

Empieza por surface/Surface/SampleListFiller.cs, en la rama itemsPath identificada en el issue dentro de BuildGroups. Sigue cómo la lista items generada por el planner llega a la colección Members del grupo tipado y, después, revisa surface/Surface/SampleObjects.cs para entender cómo se manejan las propiedades inicializadas. El trabajo estará terminado cuando la vista previa agrupada muestre los valores de ejemplo generados en lugar de "Runtime item" para los elementos creados mediante ItemsPath.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
Problem

When Sample Data is enabled in the Visual Studio XAML Previewer (zateutsch-xaml-previewer, v0.3.15), a grouped ListView bound to a CollectionViewSource with IsSourceGrouped="True" and ItemsPath="Members" ignores the planner's generated sample rows ("Sample item 1", "Sample item 2", "Sample item 3") whenever the item class has a non-empty C# property initializer (e.g., public string Name { get; set; } = "Runtime item";). Every child row across all groups displays "Runtime item" instead.

Smallest repro
  1. Define a group class with an ItemsPath collection and an item class with a default property initializer:
    public sealed class SampleItem
    {
        public string Name { get; set; } = "Runtime item";
    }
    
    public sealed class ItemGroup
    {
        public string Name { get; set; } = "";
        public ObservableCollection<SampleItem> Members { get; set; } = [];
    }
    
  2. Bind a ListView through a CollectionViewSource with ItemsPath="Members":
    <Page.Resources>
        <CollectionViewSource x:Key="PathGroups" Source="{x:Bind Model.Groups}" IsSourceGrouped="True" ItemsPath="Members"/>
        <DataTemplate x:Key="GroupRow" x:DataType="m:SampleItem">
            <TextBlock Text="{x:Bind Name}"/>
        </DataTemplate>
    </Page.Resources>
    <ListView ItemsSource="{Binding Source={StaticResource PathGroups}}" ItemTemplate="{StaticResource GroupRow}"/>
    
  3. Open the page in the XAML Previewer and toggle Sample Data: On.
  • Actual result: Group headers show "Sample group 1" and "Sample group 2", but every child item in every group shows "Runtime item".
  • Expected result: Child items in each group show the planner's generated sample values ("Sample item 1", "Sample item 2", "Sample item 3"), matching the behavior of IList-subclass groups.
Root cause & smallest fix

In surface/Surface/SampleListFiller.cs (BuildGroups, lines 273–307):

var items = new List<object>();
if (g.TryGetProperty("Items", out var rowsOfGroup) && rowsOfGroup.ValueKind == JsonValueKind.Array)
{
    int ii = 0;
    foreach (var row in rowsOfGroup.EnumerateArray())
    {
        if (Convert(row) is not { } v) continue;
        if (itemType is not null && SampleObjects.Create(itemType, v as IReadOnlyDictionary<string, object>, ii) is { } obj) v = obj;
        items.Add(v);
        ii++;
    }
}

object? group = null;
if (groupType is not null &&
    SampleObjects.Create(groupType, new Dictionary<string, object> { ["Key"] = key }, gi) is { } typed)
{
    if (string.IsNullOrEmpty(itemsPath) && typed is System.Collections.IList l && !l.IsReadOnly && !l.IsFixedSize)
    {
        l.Clear();
        foreach (var item in items) l.Add(item);
        group = typed;
    }
    else if (!string.IsNullOrEmpty(itemsPath))
    {
        group = typed; // <-- `items` (built with planner rows) is discarded!
    }
}

When itemsPath is non-empty ("Members"), BuildGroups constructs items using the planner rows (row), but then discards items and keeps the Members collection that SampleObjects.Create(groupType, ...) auto-filled with row: null. Inside SampleObjects.Fill (line 146 of surface/Surface/SampleObjects.cs), when row is null, if (!IsUnset(current, p.PropertyType)) return; sees that Name is already "Runtime item" and skips generating a sample value.

Smallest fix: In the else if (!string.IsNullOrEmpty(itemsPath)) branch of SampleListFiller.BuildGroups, populate the itemsPath collection property on typed using the items list that was already constructed with the planner's rows (just as the IList branch clears and populates l with items).

Version
  • Branch / PR: zateutsch-xaml-previewer (#323)
  • Commit: 00927d1c049b59160ec4dd26b38f09ab5caed9d9 (WinUIXamlPreview.vsix v0.3.15, CI run 41725914148)
Lenguaje dominante
TypeScript
Estrellas
15
Forks
4
Merge medio
9 d 22 h
PR fusionados (30 d)
7

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/WinAppVSCE

Todos los issues de microsoft/WinAppVSCE

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.