嘿gus我有按钮:
GetData();
dataGrid1.ItemsSource = DriverCollection.ToList();
当我点击它时,datagrid不会只填充两行(我的集合包含两行),这是空的,非常窄
这是我的班级
private class DriverData
{
public string DriverName { get; set; }
public decimal DriverSalary { get; set; }
}
收藏:
private ObservableCollection<DriverData> _DriverCollection = new ObservableCollection<DriverData>();
private ObservableCollection<DriverData> DriverCollection
{
get { return _DriverCollection; }
}
GetData方法&lt;&lt;它的工作正确集合充满了两行:
for (int i = 0; i < FilteredDriverNamesList.Count; i++)
{
_DriverCollection.Add(new DriverData { DriverName = FilteredDriverNamesList[i], DriverSalary = _DriverSalarys[i] });
}
和网格:
<sdk:DataGrid AutoGenerateColumns="False" Name="dataGrid1" FontSize="14" Margin="12,0,0,0"
HorizontalAlignment="Left" Width="549" Height="273" VerticalAlignment="Top" ItemsSource="{Binding DriverCollection}">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding DriverName}" Width="200"/>
<sdk:DataGridTextColumn Binding="{Binding DriverSalary}" Width="140"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
编辑:我已经解决了我在课堂上公开编辑的问题 感谢
答案 0 :(得分:1)
好的,到目前为止你做的很棒,
您可以更改DriverCollection并将其公开。即
public ObservableCollection<DriverData> DriverCollection
{
get { return _DriverCollection; }
}