You can create this kind of GridView by setting the ItemsPanel in the WrapPanel , you can get the WrapPanel on Jerry Nixon's blog . Here is the code.
Xaml
<GridView x:Name="gv"> <GridView.ItemsPanel> <ItemsPanelTemplate> <local:WrapPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </GridView.ItemsPanel> <GridView.ItemTemplate> <DataTemplate> <Grid Height="140" Width="{Binding MyWidth}"> <Grid.Background> <SolidColorBrush Color="{Binding MyColor}" /> </Grid.Background> <TextBlock FontSize="20" VerticalAlignment="Bottom" Margin="10,0,0,10"> <Run Text="{Binding MyWidth}" /> </TextBlock> </Grid> </DataTemplate> </GridView.ItemTemplate> </GridView>
WITH#
protected override void OnNavigatedTo(NavigationEventArgs e) { var list = new List<ViewModel>() { new ViewModel(110, Colors.LawnGreen), new ViewModel(50, Colors.DarkBlue), new ViewModel(130, Colors.Firebrick), new ViewModel(60, Colors.RosyBrown), new ViewModel(100, Colors.IndianRed), new ViewModel(210, Colors.BurlyWood), new ViewModel(150, Colors.Turquoise) }; gv.ItemsSource = list; } public class ViewModel { public double MyWidth { get; set; } public Color MyColor { get; set; } public ViewModel(double _MyWidth, Color _MyColor) { MyWidth = _MyWidth; MyColor = _MyColor; } }
source share