2014-06-19 3 views
4

나는 코드에서 설정 행과 열을 관리하지만, XAML이 설정을 이동할 수 없습니다 : 다음Xamarin.Forms에서 행/열 정의를 설정하는 방법 Xaml?

grid.RowDefinitions = new RowDefinitionCollection { 
    new RowDefinition { Height = new GridLength(1, GridUnitType.Star) } 
}; 
grid.ColumnDefinitions = new ColumnDefinitionCollection { 
    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } 
}; 

이 작동하지 않습니다

<Grid x:Name="grid" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    ... 
</Grid> 

을 내가 가져가 관리하는 documentation에서 유일한 C# 구현

+1

가 정의 할 수있는 샘플입니다? 귀하의 xaml은 유효 해 보입니다. 올바른 방법입니다. –

+0

row = 0 및 col = 0 인 그리드 내용에 대해 모든 화면 공간을 제공하지는 않습니다. 대신 내용이 양식의 왼쪽 위 모서리로 이동됩니다. 비록 코드에서 정의를 사용하더라도 - 작동하면 센터로가는 내부 컨트롤에 모든 공간을 제공합니다. –

+0

이 것이 작동하도록되어 있습니다. 당신이하고있는 것에 대한 완전한 예제, 코드, xaml을 게시 할 수 있습니까? 고마워 –

답변

7

또한 하나의 셀 (하나의 행/열, 하나의 셀이 가득 찬 격자가 필요한 이유는 모르겠지만)이있는 격자에 대해서도 동일한 동작 (채우지 않고 확장하지 않음)을 얻습니다. 화면 크기) ,하지만 그것은 2 x 2, 3 x 3 셀 그리드 (아직 다른 시도하지 않은)에 대해 잘 작동하는 것 같습니다.

Xamarin Forms에서 Height = ""및 Width = ""속성이 필요하지만 기본으로 가정 할 때 WPF에서는 필요하지 않다고 생각합니다. 여기

<ContentPage.Content> 
    <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="*"></RowDefinition> 
    <RowDefinition Height="*"></RowDefinition> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="*"></ColumnDefinition> 
    <ColumnDefinition Width="*"></ColumnDefinition> 
    </Grid.ColumnDefinitions> 

    <Button Grid.Row="0" Grid.Column="0" Text="1"></Button> 
    <Button Grid.Row="1" Grid.Column="1" Text="2"></Button> 
    </Grid> 
</ContentPage.Content> 
0

"는 작동하지 않습니다"

<Grid> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="*" /> 
    <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <Label Text="Top Left" Grid.Row="0" Grid.Column="0" /> 
    <Label Text="Top Right" Grid.Row="0" Grid.Column="1" /> 
    <Label Text="Bottom Left" Grid.Row="1" Grid.Column="0" /> 
    <Label Text="Bottom Right" Grid.Row="1" Grid.Column="1" /> 
</Grid> 
관련 문제