Reputation: 736
Apologize if i am wrong, i am new to metro apps i need multiple grids fit into single grid view,This can be done using XAML by following code
<GridView x:Name="qw" Width="1052" Height="554" HorizontalAlignment="Left" Background="Black">
<Grid Background="White" Height="284" Width="270"/>
<Grid Background="White" Height="284" Width="270"/>
<Grid Background="White" Height="284" Width="270"/>
<Grid Background="White" Height="284" Width="270"/>
<Grid Background="White" Height="284" Width="270"/>
</GridView>
But i want to do this in C#, Please help me. Thanks in advance
Upvotes: 0
Views: 1490
Reputation: 30698
You can declare a data template (that has Grid), and bind ItemsSource to some collection property of ViewModel.
There will be as many grid, in GridView as many items in ViewModel Collection.
XAML code
< GridView x:Name="qw" ItemsSource="{Binding Items}" Width="1052" Height="554" HorizontalAlignment="Left" Background="Black">
< GridView.ItemTemplate>
< DataTemplate>
< Grid Background="White" Height="284" Width="270"/>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
View Model code
public ObservableCollection<String> Items { get; set; }
...
Items = new ObservableCollection<string>();
this.Items.Add("Item 1");
this.Items.Add("Item 1");
this.Items.Add("Item 1");
this.Items.Add("Item 1");
Upvotes: 1