2017-11-25 7 views
0

우선 xamarin 양식으로 시작하는 im, listviews를 사용하여 관리했습니다. 그러나 격자에 관해서는 혼란 스러워요. 기본적으로 필요한 것은 객체를 이처럼 행동 그리드의 시리즈 : 행당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

그러나, 내가 가진 그리드를 채우는 방법을 잘 모릅니다 정보를 동적으로 listview는 바인드 명령을 사용하는 것부터 매우 간단합니다. 여기에는 아이디어가 없습니다. 누군가 올바른 방향으로 나를 가리 키도록 할 수 있습니까? 덕분에 .

+0

Grid는 데이터 바인딩을 지원하지 않는 레이아웃 컨테이너입니다. 그리드의 Children 컬렉션을 사용하여 런타임에 컨트롤을 그리드에 추가 할 수 있습니다. – 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++; 
    } 

}