C#/WPF
WPF tutorial - The StackPanel
광그로
2017. 6. 22. 17:23
이전의 WrapPanel의 경우 공간이 부족하게 되면, 다음 줄로 넘어가 시작하였지만, StackPanel은 무시하고 바로 나타납니다.
WrapPanel과 마찬가지로 Orientation의 값을 조정하여, 수평/수직으로 나열할 지 정할 수 있습니다.
기본 값으로는 Vertical이 설정되어 있습니다.
또한 StackPanel의 경우 height과 width를 수평인 경우, 수직인 경우에 맞춰 기본적으로 확장시켜 나타냅니다.
1 2 3 4 5 6 7 8 | <StackPanel Orientation="Horizontal"> <Button >Test button 1</Button> <Button Height="60">Test button 2</Button> <Button>Test button 3</Button> <Button Height="40">Test button 4</Button> <Button>Test button 5</Button> <Button>Test button 6</Button> </StackPanel> | cs |
기본적으로 VerticalAlignment 혹은 HorizontalAlignment 의 값이 Stretch로 지정되어 있어 위와 같이 나오게 됩니다.
이 또한 ...Alignment의 속성을 변경시켜 주면 해결됩니다!
1 2 3 4 5 6 7 8 | <StackPanel Orientation="Horizontal"> <Button VerticalAlignment="Top">Button 1</Button> <Button VerticalAlignment="Center">Button 2</Button> <Button VerticalAlignment="Bottom">Button 3</Button> <Button VerticalAlignment="Bottom">Button 4</Button> <Button VerticalAlignment="Center">Button 5</Button> <Button VerticalAlignment="Top">Button 6</Button> </StackPanel> | cs |