Condividi tramite


Image and text list (collection) template (XAML)

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

Use this item template with a ListViewto display a collection with image and text data.

This example shows the DataTemplate and a ListView that uses the template.

<DataTemplate x:Key="ImageTextListCollectionTemplate">          
    <StackPanel Orientation="Horizontal" Width="500" Height="130">
        <Border Height="110" Width="110" Margin="10,10,0,10">
            <Image Source="/SampleImage.png" Stretch="UniformToFill"/>
        </Border>
       <StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="0,10,0,0">
            <TextBlock Text="Aellus nec ipsum tempor id laoreet viverra" 
                       Margin="10,0,0,0" Width="350" Height="20" TextTrimming="WordEllipsis" />
            <TextBlock Text="Phasellus faucibus" 
                       Margin="10,2,0,0" Width="350" Height="14" TextTrimming="WordEllipsis" 
                       HorizontalAlignment="Left" FontSize="9" Opacity="0.49"/>                        
            <TextBlock Text="A Proin leo nulla, scelerisque non congue nec, facilisis a tellus. Sed varius rhoncus metus, et condimentum ipsum luctus ullamcorper." 
                       Margin="10,2,0,0" Width="350" TextTrimming="WordEllipsis" TextWrapping="Wrap"/>
        </StackPanel>
    </StackPanel>            
</DataTemplate>
<ListView x:Name="ImageTextListCollectionGrid" Width="500" 
          VerticalAlignment="Stretch" HorizontalAlignment="Left" 
          CanReorderItems="True" CanDragItems="True" 
          ItemTemplate="{StaticResource ImageTextListCollectionTemplate}"/>