【发布时间】:2016-02-05 05:06:56
【问题描述】:
我正在尝试在 WPF 中重新创建以下响应式网格(请参阅下面的“所需行为”链接)。但是,我正在努力寻找实现这一目标的最佳方法。
理想情况下,我想要一个水平的图块列表,这些图块的大小会增加和缩小以适应可用空间。作为一个起点,我有一个可以换行的列表框,但是在重新调整大小时会留下空白。任何指针将不胜感激。
当前换行面板:
:
我当前的代码:
<Window x:Class="WrappingListbox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Wrapping Listbox"
Width="525"
Height="350"
mc:Ignorable="d">
<Grid>
<ListBox x:Name="listbox1" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="20" HorizontalAlignment="Center">
<Viewbox>
<Grid x:Name="backgroundGrid"
Width="60"
Height="60">
<Rectangle x:Name="Rect" Fill="green" />
</Grid>
</Viewbox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<WrapPanel HorizontalAlignment="Left" VerticalAlignment="Top" />
</Grid>
【问题讨论】:
-
您已经硬编码了网格的宽度和高度,它们不会扩大或缩小以填充空间。