3

私はWPFを持っておりDataGrid、それはにバインドされていList<Person> peopleます。

public class Person
{
    public string Name{get;set;}
    public string LastName{get;set;}
    public string Address{get;set;}
    public int Age{get;set;}
}

public void ShowPeople()
{
     myDataGrid.ItemsSource = people;
}

それはすべてうまく表示されますが、AddressTextBoxDataGrid.

XAML コードを次のように変更しました。

   <DataGrid x:Name="myDataGrid">
        <DataGridTemplateColumn Header="Address">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Path=Address}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid>

これは機能していません。エラーが発生しています。

ItemsSource を使用する前に、Items コレクションを空にする必要があります。

助けてください。ありがとう、

4

1 に答える 1

7

ColumnsXAML に次のプロパティがありません。

<DataGrid x:Name="myDataGrid">
    <DataGrid.Columns> <-- This is missing in your code!
        <DataGridTemplateColumn Header="Address">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Path=Address}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>
于 2013-03-22T20:09:25.633 に答える