如何在 ListBox 中的项目之间显示分隔符? [英] How to show a divider between items in a ListBox?
问题描述
我在 Windows Phone 7 应用程序中使用 ListBox 控件,我想在列表行之间显示分隔线/线.尽管许多(不是 wp7)ListBox 示例似乎有一个分隔符,但我无法找到有关此的任何信息.
I am using a ListBox control in a Windows Phone 7 application, and I would like to show a divider/line between the list rows. I have not been able to find any information about this, although many (not wp7) ListBox examples seem to have a divider.
推荐答案
受到 NestorArturo 的启发,发现了边境管制.
Got inspired by NestorArturo and found out about the Border control.
将您的 ItemTemplate 内容包装在 Border 控件中并指定 BorderThickness 和 BorderBrush 非常容易.我这样做是因为它不需要更改我在 ItemTemplate 中的 Grid.
It is very easy to wrap your ItemTemplate content in a Border control and specify the BorderThickness and BorderBrush. I went this way, because it doesn't require changes to my Grid in the ItemTemplate.
此处描述了边界控制:http://www.silverlightshow.net/items/Using-the-Border-control-in-Silverlight-2-Beta-1-.aspx.
The Border control is described here: http://www.silverlightshow.net/items/Using-the-Border-control-in-Silverlight-2-Beta-1-.aspx.
下面你可以看到我是如何使用它的:
Below you can see how I use it:
<ListBox Background="White" ItemsSource="{Binding Mode=OneWay, Path=MyPath}" Name="listName" SelectionChanged="listName_SelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
here --> <Border BorderThickness="0,10,0,10" BorderBrush="Black">
<Grid Width="auto" HorizontalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="48" />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" FontSize="36" FontWeight="Bold" Grid.Column="0" Foreground="Black" Text="{Binding Path=Title}" Name="title"/>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" Grid.Column="1" Foreground="Black" Text="{Binding Path=Location}" Name="location"/>
<Image VerticalAlignment="Center" Grid.Column="2" Width="48" Height="48" Source="ApplicationIcon.jpg"/>
</Grid>
and here --> </Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这篇关于如何在 ListBox 中的项目之间显示分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!