Silverlight数据网格不绑定
嘿,我有按钮:
GetData();
dataGrid1.ItemsSource = DriverCollection.ToList();
当我单击它时,数据网格不会填充,仅添加两行(我的集合包含两行),这是空的且非常窄,
这是我的类
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>
编辑:我已经解决了我在班级上用公共编辑的问题 谢谢
Hey gus i have button:
GetData();
dataGrid1.ItemsSource = DriverCollection.ToList();
When i click it datagrid does not filling only adding two rows (my collection contains two rows) which is empty and very narrow
this is my class
private class DriverData
{
public string DriverName { get; set; }
public decimal DriverSalary { get; set; }
}
collection :
private ObservableCollection<DriverData> _DriverCollection = new ObservableCollection<DriverData>();
private ObservableCollection<DriverData> DriverCollection
{
get { return _DriverCollection; }
}
GetData method << its works correctly collection is filling with two rows:
for (int i = 0; i < FilteredDriverNamesList.Count; i++)
{
_DriverCollection.Add(new DriverData { DriverName = FilteredDriverNamesList[i], DriverSalary = _DriverSalarys[i] });
}
and the grid:
<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>
Edit: I have solved the problem i edited private with public on my class
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,到目前为止您所做的工作非常出色,
您可以更改 DriverCollection 并将其公开吗? IE
Ok, this is great job you have done so far,
Can you change DriverCollection and make it public. i.e