Get the number of rows in a WrapPanel?

I have a list box that implements its ItemPanelTemplate as a WrapPanel. I need to count the number of rows for navigation purposes

<ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Grid.IsSharedSizeScope="True" /> </ItemsPanelTemplate> <ListBox.ItemsPanel> <ListBox> 

Is there any direct way ?.

+4
source share
1 answer

Since WrapPanel is flow control, you will have to do some calculations to determine how many objects are right for you.

Take the ActualHeight WrapPanel property, split it into the ActualHeight object (or ItemHeight property) of the object that you place in the panel. This should give you the number of lines:

 int numRows = (int)(WrapPanel.ActualHeight / Item.ActualHeight); 

or

 int numRows = (int)(WrapPanel.ActualHeight / WrapPanel.ItemHeight); 

This calculation will be disabled if you have any fields, but you must consider them.

(You can do the same with ActualWidth and ItemWidth to get the number of columns).

+6
source

Source: https://habr.com/ru/post/1447367/


All Articles