【发布时间】:2012-01-20 10:11:45
【问题描述】:
嘿,我有按钮:
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 方法
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>
编辑:我已经解决了我在课堂上私下编辑的问题 谢谢
【问题讨论】:
标签: silverlight-4.0 datagrid observablecollection