Witam,
Potrzebuję DataGrid z dowolną ilością kolumn. Doszedłem do tego, że definiuję sobie DataTemplate:

<Window.Resources>
        <DataTemplate x:Key="Wzor" DataType="DataGridCell">
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding Obrazek}" />
                <TextBox Width="50" Text="{Binding Opis}" />
            </StackPanel>
        </DataTemplate>
</Window.Resources>

W oknie defininiuję DataGrid:

        <DataGrid x:Name="dataGrid" AutoGenerateColumns="False" Height="497" Width="617" HeadersVisibility="Column">
        </DataGrid>

W kodzie okna stwotzyłem procedurę dodającą kolumny:

public void GenerateTemplateColumns(int ile) {
dataGrid.Columns.Clear();
for (int index = 0; index < ile; index++) {
dataGrid.Columns.Add(new DataGridTemplateColumn { Header = "Kolumna" + index,
CellTemplate = (DataTemplate)FindResource("Wzor") });
}
}

I przygotowałem dane dla testów (bez większej finezji :), to są dane do testów  :) ):
<code class="c#">
        class Element {
            public string Opis { get; set; }
            public Uri Obrazek { get; set; }
        }
GenerateTemplateColumns(3)

object[] dp = new object[3];
        
        List<Element> napisy1 = new List<Element>();

        napisy1.Add(new Element() { Opis = "00", Obrazek = new Uri(@"c:\tmp\biedronka.jpg") });
        napisy1.Add(new Element() { Opis = "01", Obrazek = new Uri(@"c:\tmp\biedronka.jpg") });
        napisy1.Add(new Element() { Opis = "02", Obrazek = new Uri(@"c:\tmp\biedronka.jpg") });

        Element[] napisy2 = new Element[3];
        napisy2[0] = new Element();
        napisy2[0].Opis = "10";
        napisy2[0].Obrazek = new Uri(@"c:\tmp\biedronka.jpg");
        napisy2[1] = new Element();
        napisy2[1].Opis = "11";
        napisy2[1].Obrazek = new Uri(@"c:\tmp\biedronka.jpg");
        napisy2[2] = new Element();
        napisy2[2].Opis = "12";
        napisy2[2].Obrazek = new Uri(@"c:\tmp\biedronka.jpg");
        Element[] napisy3 = new Element[3];
        napisy3[0] = new Element();
        napisy3[0].Opis = "20";
        napisy3[0].Obrazek = new Uri(@"c:\tmp\biedronka.jpg");
        napisy3[1] = new Element();
        napisy3[1].Opis = "21";
        napisy3[1].Obrazek = new Uri(@"c:\tmp\biedronka.jpg");
        napisy3[2] = new Element();
        napisy3[2].Opis = "22";
        napisy3[2].Obrazek = new Uri(@"c:\tmp\biedronka.jpg");

        dp[0] = napisy1;
        dp[1] = napisy2;
        dp[2] = napisy3;

        this.dataGrid.ItemsSource = dp;

Niestety efekt jest taki, że w każdym wierszu powtarzany trzy razy jest pierwszy element, zamiast wszystkich po kolei. W załączniku znajduje się screen takiego grida. W pierwszym wierszu mamy elementy 00, w drugim 10, w trzecim 20 achciałbym otrzymać:
00, 01, 02
10, 11, 12
20, 21, 22

Czy zna ktoś rozwiązanie tej zagadki ?
Będę wdzięczny za wszelkie sugestie. Dołączyłem dodatkowo plik zip z projektem.
Pozdrawiam
Paweł