解决方法
受到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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。