У меня есть DataGrid с включенным TextWrapping в ячейках. Это означает, что строки не имеют одинаковую высоту. У меня вопрос, как я могу пройтись по строкам и получить высоту каждого из них?
Как выглядит DataGrid:
![enter image description here](https://i.stack.imgur.com/khjLT.png)
Вот код сетки данных:
public ObservableCollection<Article> persons = new ObservableCollection<Article>();
for(int i = 0; i < 35; i++)
{
persons.Add(new Article("Restless legs syndrome and tis correlation with other sleep problems in the general adult population of Japan",
"Minori Enomoto, Lan Li, Sayaka Aritake, Yukihiro Nagase, Tatsuhiko Kaji, Hirokuni Tagaya, Masato Matsuura, Yoshitaka Kaneita, Takashi Ohida, Makoto Uchiyama",
"Sleep and Biological Rhythms",
4));
}
dgMain.ItemsSource = persons;
Вот как я это посчитал:
private void btnTest_Click(object sender, RoutedEventArgs e)
{
int k = 0;
var rows = GetDataGridRows(dgMain);
foreach (DataGridRow r in rows)
{
var rowHeight = r?.ActualHeight;
k++;
}
MessageBox.Show(k.ToString());
}
А вот и класс статьи:
public class Article
{
private string _title;
public string Title
{
get { return this._title; }
set { this._title = value; }
}
private string _authors;
public string Authors
{
get { return this._authors; }
set { this._authors = value; }
}
private string _journal;
public string Journal
{
get { return this._journal; }
set { this._journal = value; }
}
private int _year;
public int Year
{
get { return this._year; }
set { this._year = value; }
}
public Article(string Title, string Authors, string Journal, int Year)
{
this._title = Title;
this._authors = Authors;
this._journal = Journal;
this._year = Year;
}
}