如何显示一个列表框中的项目之间的分隔线? [英] How to show a divider between items in a ListBox?

查看:68
本文介绍了如何显示一个列表框中的项目之间的分隔线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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启发,发现了有关Border控件的信息.

Got inspired by NestorArturo and found out about the Border control.

将ItemTemplate内容包装在Border控件中并指定BorderThickness和BorderBrush非常容易.我采用这种方式,因为它不需要在ItemTemplate中更改我的网格.

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.

此处描述了Border控件: http://www.silverlightshow.net/items/使用-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>

这篇关于如何显示一个列表框中的项目之间的分隔线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆