簡體   English   中英

使用C#在Gridview中添加多個網格

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM