Xaml UWP中列表框内的包装
我希望在我的Xaml UWP中列表框内的包装,xaml,windows-10,windows-10-mobile,windows-10-universal,Xaml,Windows 10,Windows 10 Mobile,Windows 10 Universal,我希望在我的列表框中添加WrapPanel,这样它就可以进行垂直和水平的项目包装。我能够在WindowsPhone8Sliverlight中用微软工具包实现这一点,代码如下 Windows Phone 8 <ListBox x:Name="ListSection" ItemsSource="{Binding Section}" > <ListBox.ItemsPanel> <ItemsPanelTemplate> &
列表框中添加WrapPanel
,这样它就可以进行垂直和水平的项目包装。我能够在WindowsPhone8Sliverlight中用微软工具包实现这一点,代码如下
Windows Phone 8
<ListBox x:Name="ListSection" ItemsSource="{Binding Section}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" ></toolkit:WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="20">
<Image Source="{Binding ImagePath}" Width="80" Height="80"></Image>
<TextBlock Style="{StaticResource PhoneTextBlockBase}"
HorizontalAlignment="Center"
Foreground="Black"
Text="{Binding Header}"
FontWeight="Bold"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
我知道微软工具包在UWP中不可用,我是否有可能在UWP中实现这种行为
UWP不工作
<ListBox x:Name="ItemsListBox" ItemsSource="{Binding Section}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel HorizontalAlignment="Stretch"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding ImagePath}" Width="80" Height="80"></Image>
<TextBlock HorizontalAlignment="Center"
Foreground="Black"
Text="{Binding Header}"
FontWeight="Bold"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
谢谢 项目中有一个用于UWP的工具包包装端口
你可以从我这里得到它
然后在页面中
添加此前缀:
xmlns:toolkit="using:WinRTXamlToolkit.Controls"
现在您可以像以前一样使用
@ARH您需要创建一个自定义的Panel类,该类继承Panel类并重写MeasureOverride和ArrangeOverride方法。请查看以下链接以获取参考。
必须将ListView和ItemsRapGrid用作ItemsPanel
您可以通过示例查看此处的MSDN文档
此示例适用于GridView,但与ListView相同
<GridView>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
您可以使用属性方向来垂直或水平设置项目。可从中获得包装
下面是一些示例代码(使用v5.0.0
):
。。。
xmlns:toolkit=“使用:Microsoft.toolkit.Uwp.UI.Controls”
...
注意:此处的ListItemView
样式删除了多余的填充,允许WrapPanel
间距属性作为布局的控制点。能否请您更详细地解释一下“不工作”。到底是什么不起作用了?谢谢,@chrisF列表框的项目全部水平显示,它没有包装GraceF抱歉它没有重复(我知道使用变量SizedWrapGrid)在示例代码中有一个StackPanel作为ItemsPanel。将ItemsPanelTemplate设置为ItemsWrapGrid
...
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
...
<ListView
Name="WrapPanelContainer"
Width="310" Height="200"
Margin="0,40,0,0"
HorizontalAlignment="Left"
Background="LightBlue"
IsItemClickEnabled="True"
>
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="MinWidth" Value="0"/>
<Setter Property="MinHeight" Value="0"/>
<Setter Property="Padding" Value="0"/>
</Style>
</ListView.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel VerticalSpacing="10" HorizontalSpacing="10" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<Rectangle Fill="Red" Width="100" Height="50"/>
<Rectangle Fill="Blue" Width="200" Height="50"/>
<Rectangle Fill="Green" Width="50" Height="50"/>
<Rectangle Fill="Yellow" Width="150" Height="50"/>
</ListView>