Как в datagrid вывести данные из двух классов

Рейтинг: 0Ответов: 0Опубликовано: 15.05.2023

Есть два класса, которые отвечают за модели данных

internal class CandiesModel
    {
        public int id { get; set; }
        public string type { get; set; }
        public string name { get; set; }
        public decimal weight { get; set; }
        public decimal price { get; set; }
        public string producer { get; set; }
        public string country { get; set; }
        public CandiesModel(int id, string type, string name, decimal weight, decimal price, string producer, string country)
        {
            this.id = id;
            this.type = type;
            this.name = name;
            this.weight = weight;
            this.price = price;
            this.producer = producer;
            this.country = country;
        }
    }

И второй

internal class SalesModel
    {
        public int id { get; set; }
        public DateTime date { get; set; }
        public int candyid { get; set; }
        public CandiesModel candy { get; set; }
     
        public SalesModel(int id, DateTime date, CandiesModel candy)
        {
            this.id = id;
            this.date = date;
            this.candy = candy;
        }
    }

Вывод осуществляется следующим образом:

private BindingList<SalesModel> salesData = new BindingList<SalesModel>(); //сюда записываются данные
DataGrid.ItemsSource = salesData;

Вторая модель данных содержит свои поля и объект первой модели. Как в DataGrid вывести данные таким образом, чтобы выводились сначала поля из класса SalesModel(id, date), а при выводе candy, выводились все поля из класса CandiesModel.

Ответы

Ответов пока нет.