【问题标题】:UWP align ListViewItem to bottomUWP 将 ListViewItem 对齐到底部
【发布时间】:2016-02-25 08:05:19
【问题描述】:
这是简单的列表视图:
<ListBox>
<ListBoxItem Name="Home">
<RelativePanel>
<TextBlock Text=""/>
</RelativePanel>
</ListBoxItem>
<ListBoxItem Name="Map">
<RelativePanel>
<TextBlock Text=""/>
</RelativePanel>
</ListBoxItem>
<ListBoxItem Name="Settings">
<RelativePanel>
<TextBlock Text=""/>
</RelativePanel>
</ListBoxItem>
</ListBox>
如何将名称为 Settings 的最后一个孩子添加到列表视图的底部?这样Map 和Settings 之间的空间就会扩大到最大
【问题讨论】:
标签:
c#
.net
xaml
win-universal-app
【解决方案1】:
只需使用 4 行的网格,例如 Auto、Auto、*、Auto,然后将 Settings 放在最后一行。
【解决方案2】:
我不确定它是否也适用于 ListBox,但在 ListView(它只是 ListBox 的更新和更好的版本)中,您可以通过将 ListViewItem 放在页脚中来将它放在 ListView 的最底部,像这样:
<ListView>
<ListViewItem Content="Home" />
<ListViewItem Content="Map" />
<ListView.Footer>
<ListViewItem Content="Settings" />
</ListView.Footer>
</ListView>
编辑:我刚刚发现单击页脚不是由 ItemClick 事件处理的,不幸的是我还没有找到任何可以处理它的事件。
【解决方案3】:
我就是这样做的。将行高设置为“*”。希望这会有所帮助。
<RelativePanel>
<ListBox RelativePanel.AlignTopWithPanel="True" VerticalAlignment="Stretch">
<ListBoxItem Name="Home" >
<TextBlock Text="Home"/>
</ListBoxItem>
<ListBoxItem Name="Map">
<TextBlock Text="Map"/>
</ListBoxItem>
</ListBox>
<ListBox RelativePanel.AlignBottomWithPanel="True">
<ListBoxItem Name="Settings">
<TextBlock Text="Settings"/>
</ListBoxItem>
</ListBox>
</RelativePanel>
【解决方案4】:
试试这个:
<ListView Name="MyListView" VerticalAlignment="Stretch" ItemsSource="{Binding MyListItems}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel VerticalAlignment="Bottom"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>