[英]Why DataGrid adds empy elements on DataGrid.Items.Add?
In WPF i need, then i click button, i`m adding new row with information to DataGrid. 在WPF中,我需要单击按钮,然后将包含信息的新行添加到DataGrid。 But than I hit the buttin, new rows a creating, but its fill emlpty, not with any string.
但是比我打的还要多,新的行创建了,但是填充了空白,没有任何字符串。 How to fix it?
如何解决? Thanks for advance.
感谢前进。
XAML code: XAML代码:
<DataGrid Name="ClicksGrid" HorizontalAlignment="Left" Height="204" Margin="348,20,0,0" AutoGenerateColumns="False" CanUserAddRows="True" VerticalAlignment="Top" Width="354">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" IsReadOnly="True" Binding="{Binding Path=ID}" Width="40" />
<DataGridTextColumn Header="ClickType" IsReadOnly="True" Binding="{Binding Path=Type}" Width="120" />
<DataGridTextColumn Header="Time" IsReadOnly="True" Binding="{Binding Path=Time}" Width="193"/>
</DataGrid.Columns>
</DataGrid>
c# code: C#代码:
// click class
public class Click
{
public string ID;
public string Type;
public string Time;
public Click(string ID, string Type, string Time)
{
this.ID = ID;
this.Type = Type;
this.Time = Time;
}
}
// by button clicking calling this method:
private void TableUpdate()
{
IDnum++;
//test strings:
var cl = new Click("asd", "sdad", "asds");
ClicksGrid.Items.Add(cl);
}
Change Click class in this way: 以这种方式更改Click类:
public class Click
{
public string ID { get; set; }
public string Type { get; set; }
public string Time { get; set; }
public Click(string ID, string Type, string Time)
{
this.ID = ID;
this.Type = Type;
this.Time = Time;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.