如何在列表框中的每个项目后面放置一条水平线

时间:2014-02-27 07:55:23

标签: c# xaml windows-phone-7

我正在为Windows Phone 7构建一个应用程序,我在列表框中显示了一些数据。我想在每个项目后面添加一个图像,以区别于另一个项目。我的xaml代码是:

 <ListBox Name="listBox1" BorderThickness="0" Height="679" VerticalAlignment="Bottom" Margin="12,0,0,-29" Background="White" Grid.Row="1">
 <ListBox.ItemTemplate>
 <DataTemplate>
 <ScrollViewer HorizontalScrollBarVisibility="Disabled" Height="80" Width="400">
 <StackPanel Orientation="Horizontal" Margin="0,0,0,0" Background="White" Width="500">
 <Image Source="{Binding ImageBind }" HorizontalAlignment="Stretch"     VerticalAlignment="Stretch" Margin="0,0,20,10" Height="100" Width="145" />
 <StackPanel Orientation="Vertical">
      <StackPanel Orientation="Horizontal">
   <TextBlock Text="{Binding city_name}" Foreground="Red" FontFamily="Verdana" />
   <TextBlock Text=", " Foreground="Red" FontFamily="Verdana" />
    <TextBlock Text="{Binding state}" Foreground="Red" FontFamily="Verdana" />
      </StackPanel>
   <TextBlock Text="{Binding Path=city_description}" TextWrapping="Wrap" Foreground="Black" FontFamily="Verdana"></TextBlock>
    <Image Source="Image/index.jpg"/>
       </StackPanel>
     </StackPanel>
   </ScrollViewer>
    </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

index.jpg图像是我想要添加的水平线。请帮助添加该图像的位置,以便将该图像作为每个数据的分隔符

1 个答案:

答案 0 :(得分:1)

检查一下:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/e09926c2-5d53-4337-ba76-d1c786ec9ced/listbox-with-horizontal-lineseparator?forum=wpf

第一个答案

尝试这样的事情:

<ListBox Name="listBox1" BorderThickness="0" Height="679" VerticalAlignment="Bottom" Margin="12,0,0,-29" Background="White" Grid.Row="1">
 <ListBox.ItemTemplate>
 <DataTemplate>
 <ScrollViewer HorizontalScrollBarVisibility="Disabled" Height="80" Width="400">
 <StackPanel Orientation="Horizontal" Margin="0,0,0,0" Background="White" Width="500">
 <Image Source="{Binding ImageBind }" HorizontalAlignment="Stretch"     VerticalAlignment="Stretch" Margin="0,0,20,10" Height="100" Width="145" />
 <StackPanel Orientation="Vertical">
      <StackPanel Orientation="Horizontal">
   <TextBlock Text="{Binding city_name}" Foreground="Red" FontFamily="Verdana" />
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
   <TextBlock Text=", " Foreground="Red" FontFamily="Verdana" />
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
    <TextBlock Text="{Binding state}" Foreground="Red" FontFamily="Verdana" />
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
      </StackPanel>
   <TextBlock Text="{Binding Path=city_description}" TextWrapping="Wrap" Foreground="Black" FontFamily="Verdana"></TextBlock>
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
    <Image Source="Image/index.jpg"/>
       </StackPanel>
     </StackPanel>
   </ScrollViewer>
    </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

这会对你有帮助;)