Почему DataGrid добавляет элементы empy в DataGrid.Items.Add? - PullRequest
1 голос
/ 05 июня 2019

В WPF мне нужно, затем я нажимаю кнопку, я добавляю новую строку с информацией в DataGrid.Но чем я нажму на кнопку, новые строки создаются, но заполняются, а не какой-либо строкой.Как это исправить?Спасибо за продвижение.

Код 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 # код:

// 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);   
        }

1 Ответ

0 голосов
/ 05 июня 2019

Изменить класс кликов следующим образом:

    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;
        }
    }
...