拉伸堆叠面板 [英] Stretch stackpanel
本文介绍了拉伸堆叠面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用列表框创建歌曲列表,但布局有问题.
I want to create a list of songs using a listbox, but I got an issue with the layout.
目前我使用以下 xaml:
Currently I use the following xaml:
<ListBox x:Name="lstHistory" HorizontalAlignment="Stretch" Margin="12,284,0,90" Width="460">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal">
<Image Margin="5" VerticalAlignment="top" Source="{Binding Image}" />
</StackPanel>
<StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBlock Margin="8"
TextWrapping="Wrap"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Text="{Binding Name}" />
<TextBlock Margin="8"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Text="{Binding Artist}" />
<TextBlock Margin="8,0,8,8"
VerticalAlignment="Bottom"
HorizontalAlignment="Right" Text="{Binding Time}" Opacity="0.25" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我想在列表项的最右下角显示时间,但每次都显示在屏幕中间.
I would like to have the time on the far right bottom corner of the list item, but every time it ends up in the middle of the screen.
这是我得到的一个例子:
This is an example of what I get:
谁能告诉我如何安排时间?
Can anyone tell me how to get the time there?
推荐答案
HorizontalAlignment="Stretch"
不适用于 StackPanel.你应该设置一个明确的宽度(可能是 432).
HorizontalAlignment="Stretch"
won't work on a StackPanel. You should set an explicit Width (probably 432) instead.
此外,图像不需要单独位于 StackPanel 中.
Also, the Image doesn't need to be in a StackPanel all by itself.
这篇关于拉伸堆叠面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文