[英]Add multiple Grids in Gridview using C#
如果我错了,我很抱歉,我是Metro应用程序的新手,我需要将多个网格放入单个网格视图中,这可以通过以下代码使用XAML来完成
<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>
但是我想用C#做到这一点,请帮助我。 提前致谢
您可以声明一个数据模板(具有Grid),并将ItemsSource绑定到ViewModel的某些collection属性。
在GridView中,将有与ViewModel Collection中的项目一样多的网格。
XAML代码
< 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>
查看型号代码
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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.