Reputation:
I have created a GridView interface with tiles of varying sizes (like the Windows start screen). How can I position controls differently on each tile? My code currently looks like this:
<DataTemplate>
<Grid Height="500" Width="1000">
<Grid.Background>
<SolidColorBrush Color="{Binding TileColor}"/>
</Grid.Background>
<StackPanel VerticalAlignment="Top">
<TextBlock Foreground="{Binding TextColor}" FontSize="25" TextWrapping="Wrap" Text="{Binding Title}" Margin="10,10,720,0"/>
</StackPanel>
<StackPanel VerticalAlignment="Bottom">
<TextBlock Foreground="{Binding TextColor}" FontSize="20" TextWrapping="Wrap" Text="{Binding Subtitle}" Height="334" Margin="10,0,336,15" RenderTransformOrigin="0.497,0.59"/>
</StackPanel>
</Grid>
</DataTemplate>
but because of the varying tile heights it doesn't layout correctly. Is there a way I can define multiple ItemTemplates?
Thanks
Upvotes: 2
Views: 3694
Reputation: 2258
You can create multiple data templates and then u need to use DataTemplateSelector to map them to your tiles. I think this article will answer your question perfectly!
http://visualstudiomagazine.com/articles/2012/08/06/multiple-item-templates-in-windows-phone.aspx
Upvotes: 3