我有一个“Seive”类,一个 ObservableCollection seiveData 对象。
public Seive(String id)
{
SeiveIdSize = id;
Caret = 0.0;
Percent = 0.0;
Peices = 0;
Weight = 0.0;
Size = 0;
}
public String SeiveIdSize { get; set; }
public Double Weight { get; set; }
public Double Percent { get; set; }
public Double Caret { get; set; }
public uint Size { get; set; }
public uint Peices { get; set; }
在我的 xml 中:我有
<DataGrid Name="serverGrid" ItemsSource="{Binding}" .....>
<DataGrid.Columns>
<DataGridTextColumn Header="SEIVE" Width="Auto" Binding="{Binding Path=SeiveIdSize}" SortDirection="Ascending" />
<DataGridTextColumn Header="CTS" Width="Auto" Binding="{Binding Path=Caret}" />
<DataGridTextColumn Header=" % " Width="Auto" Binding="{Binding Path=Percent}" />
<DataGridTextColumn Header="PCS" Width="Auto" Binding="{Binding Path=Peices}" />
<DataGridTextColumn Header="WGT" Width="Auto" Binding="{Binding Path=Weight}" />
<DataGridTextColumn Header="SIZE" Width="Auto" Binding="{Binding Path=Size}" />
</DataGrid.Columns>
在窗口加载事件中,我在 seiveData 中填充了 2 个 seives,但我没有看到任何结果/行。
seivesData.Add(new Seive("+10"));
seivesData.Add(new Seive("+8"));
seivesDataGrid.DataContext = seivesData;
编辑:按钮事件代码:
private void saveBtn_Click(object sender, RoutedEventArgs e)
{
Seive s1 = new Seive("+2");
s1.Peices = 100;
s1.Caret = 0.41;
s1.Weight = 0.10;
seivesData.Add(s1);
Seive s = seivesData[0];
s.Caret = 0.54;
s.Weight = 0.32;
seivesData[0] = s;
seiveDG.DataContext = seivesData;
}
我哪里错了?我可以看到新添加的 Seive 的所有详细信息,但不能看到添加到第 0 个 seive 的插入符号和权重。