2017-11-25 7 views
0

まず最初にxamarinフォームから始めて、C#はリストビューを使用していましたが、グリッドに関しては混乱していましたが、基本的にオブジェクトをこのように振る舞うグリッドのセリエA:行あたりxamarinフォームのグリッド集団

2列、私はこのコードでそれを行うために管理している:

<Grid HorizontalOptions="Fill" VerticalOptions="Fill" Margin="10"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="1*" /> 
       <RowDefinition Height="1*" /> 
       <RowDefinition Height="1*" /> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="1*" /> 
       <ColumnDefinition Width="1*" /> 
      </Grid.ColumnDefinitions> 

      <!--fila 1--> 
      <StackLayout Grid.Column="0" Grid.Row="0" BackgroundColor="Blue" HorizontalOptions="Fill"></StackLayout> 
      <StackLayout Grid.Column="1" Grid.Row="0" BackgroundColor="Red" HorizontalOptions="Fill"></StackLayout> 
      <!--fila 2--> 
      <StackLayout Grid.Column="0" Grid.Row="1" BackgroundColor="Red" HorizontalOptions="Fill"></StackLayout> 
      <StackLayout Grid.Column="1" Grid.Row="1" BackgroundColor="Blue" HorizontalOptions="Fill"></StackLayout> 
      <!--fila 3--> 
      <StackLayout Grid.Column="0" Grid.Row="2" BackgroundColor="Blue" HorizontalOptions="Fill"></StackLayout> 
       <StackLayout Grid.Column="1" Grid.Row="2" BackgroundColor="Red" 
    HorizontalOptions="Fill"></StackLayout> 
    </Grid> 

enter image description here

しかし、私はグリッドを埋める方法を知りません情報を動的にリストビューは非常に単純です。なぜなら、バインドコマンドがあるからです。ここではアイデアはありません。誰かが私に正しい方向を向けることができますか?ありがとう。

+0

グリッドはデータバインディングをサポートしていないレイアウトコンテナです。グリッドの子コレクションを使用すると、実行時にグリッドにコントロールを追加できます。 – Jason

+0

@ Jasonありがとう、少なくとも私はそれを使用することができますか、私はそれがforeachのを使用して行われるだろうと思うが、私は分かりません! –

答えて

0
int row = 0; 
int col = 0; 

// data is a List<string> 
foreach (var text in data) { 
    var label = new Label() { Text = text }; 
    grid.Children.Add(box, col, row); 

    col++; 
    if (col > 1) { 
    col = 0; 
    row++; 
    } 

} 
関連する問題