我被迫从后面的代码中使用 ListView/listbox。在那我必须设置边界。我希望他们在需要时换行
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>");
相反,如果我放置一个固定宽度 Width=\"300\"
lsv.ItemsPanel = (ItemsPanelTemplate)XamlReader.Parse("<ItemsPanelTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><WrapPanel Orientation=\"Horizontal\" Width=\"300\"/></ItemsPanelTemplate>");
它工作正常
问题是我无法为包装面板设置固定宽度,我希望它扩展以填充其父级。
提前谢谢帕特里克