K
K
kr_ilya2021-12-19 00:41:29
WPF
kr_ilya, 2021-12-19 00:41:29

How to find out the size of ListBox after adding items?

Need to add to canvas ListBox
Elements in listbox - TextBlock with line wrapping enabled.
Before adding it to the canvas, you need to increase its height by the height of the listbox.

I do not set the height of the listbox hard, because it should depend on the number of elements inside.
After adding elements, how to determine what the height of the listbox will be?

ListBox previewlistBox = new ListBox();

// в цикле добавляем элементы в список
TextBlock v_answer_block = new TextBlock();
v_answer_block.Text = "текст элемента";
v_answer_block.FontWeight = FontWeights.Bold;
previewlistBox.Items.Add(v_answer_block);

//конец цикла

// тут надо определить чему будет равна высота у previewlistBox
// а затем увеличить высоту канвы
preview_canvas.Height = preview_canvas.Height + высота listbox;



previewlistBox.IsEnabled = false;
previewlistBox.Width = preview_canvas.Width;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim K, 2021-12-19
@mkvmaks

Hmm .. Enter data, update, find out the size, set the size when drawing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question