2010-06-10 9 views
2

패널을 사각형으로 채우고 패널의 크기를 조정하면 사각형의 크기도 조정해야합니다.사각형 패널 채우기

왜 다음 작동하지 않습니까?

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
    <Rectangle Fill="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
    <Rectangle Fill="Green" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
    <Rectangle Fill="Blue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
    </StackPanel> 
</Page> 

나는 때문에 자녀를 추가/열을 제거하고 재 배열의 고통의 Grid를 사용하지 않으려는 것입니다. (내가 처음에 노란색 Rectangle를 추가하고자한다면, 난 그냥 선언하기 때문이다. 내가 손으로 다른 주문을 다시 할 필요가 없습니다 StackPanel 기대했다.)

+0

주 전체 사용 가능한 크기 소요 Grid를 사용하여 방향. Rectangle의 DesiredSize가 0이기 때문에 세 직사각형 모두가 무효로 축소됩니다. –

답변

3

아니면 UniformGrid : StackPanel에 작동하지 않는 이유는 StackPanel의가 스택에서 자신의 DesiredSize를보다 아이 더를 제공 결코 것을

<UniformGrid Columns="1"> 
    <Rectangle Fill="Red"/> 
    <Rectangle Fill="Green"/> 
    <Rectangle Fill="Blue"/> 
</UniformGrid> 
+0

아하! 나는 UniformGrid에 관한 모든 것을 잊어 버렸습니다. 그것은 내가 원하는 것에 완벽하게 맞습니다. – moswald

1

당신은 StackPanel를 사용하는 그의 행동은 자녀의 크기를 취하는 것입니다.

<Grid> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Rectangle Fill="Red" Grid.Row="0" /> 
    <Rectangle Fill="Green" Grid.Row="1" /> 
    <Rectangle Fill="Blue" Grid.Row="2" /> 
</Grid> 
+0

Bleh. 그리드를 사용할 필요가없는 솔루션이 있습니까? Rectangle의 수를 늘릴 때마다 새로운 RowDefinition을 추가하지 않아도됩니다. – moswald