解决方法
受到nestorArturo的启发,发现了边境控制.
将ItemTemplate内容包装在Border控件中并指定BorderThickness和BorderBrush非常容易.我这样做了,因为它不需要在ItemTemplate中更改我的网格.
边框控件在这里描述:http://www.silverlightshow.net/items/Using-the-Border-control-in-Silverlight-2-Beta-1-.aspx.
您可以在下面看到我如何使用它:
<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,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>