I am force to use a ListView/listbox from code behind. In that I have to put borders. I wish they wrapped on a new line when needed
ListView lsv = new ListView
{
Width = 400,
Height = 200,
Background = Brushes.LimeGreen,
};
grdMain.Children.Add(lsv);
for (int iii = 0; iii < 15; iii++)
{
Border b = new Border() { BorderThickness = new Thickness(3),
BorderBrush = new SolidColorBrush(Colors.Blue), Width = 50, Height = 50
};
lsv.Items.Add(b);
lsv.ItemsPanel = (ItemsPanelTemplate)XamlReader.Parse("<ItemsPanelTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><WrapPanel Orientation=\"Horizontal\" HorizontalAlignment=\"Stretch\"/></ItemsPanelTemplate>");
Now with that the effect is the following:

instead if I put a fixed width Width=\"300\"
lsv.ItemsPanel = (ItemsPanelTemplate)XamlReader.Parse("<ItemsPanelTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><WrapPanel Orientation=\"Horizontal\" Width=\"300\"/></ItemsPanelTemplate>");
it works properly
the problem is that I can't put a fixed width for the wrap panel and I want it to extend to fill its parent.
Thank you in advance Patrick

You can try doing the following...
Where you will have a helper method
Note, I have note compiled this code as am on a phone.