Tôi gặp sự cố khi gắn List
vào một số DataGrid
trong WPF. Hãy để tôi giải thích những gì tôi đã thử.Danh sách liên kết tới DataGrid
public struct SomeInfo
{
public string Name;
public string Description;
public string ID;
}
List<SomeInfo> arrSomeInfo;
arrSomeInfo
chứa nhiều mục cấu trúc SomeInfo
.
Các DataGrid
trông giống như sau:
<DataGrid Name="grdMailbag" AutoGenerateColumns="False" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn x:Name="cID" Binding="{Binding ID}" Header="ID" />
<DataGridTextColumn x:Name="cName" Binding="{Binding Name}" Header="Name" />
<DataGridTextColumn x:Name="cDescription" Binding="{Binding Description}" Header="Description" />
</DataGrid.Columns>
</DataGrid>
Tôi đã thử những điều sau đây nhưng không thành công:
this.grdMailbag.ItemsSource = arrSomeInfo; //Didn't worked
this.grdMailbag.DataContext= arrSomeInfo; // Didn't worked
gì đang xảy ra là họ sẽ bổ sung các hàng theo List arrSomeInfo
nhưng tất cả các hàng là chỗ trống.
thay đổi thành thuộc tính đã hoạt động .. Cảm ơn – chrismasters