본문 바로가기
프로그래밍

[WPF]레이아웃

by BlueOcean&Shark 2019. 2. 1.

기본 레이아웃 속성

 - 기본레이아웃 속성들은 FramworkElement로 부터 상속된다.

1)   

   : ActualHeight   ->  렌더링된 개체의 높이값

   : ActualWidth    ->  렌더링된 개체의 너비값

   : Hight Width

   : MaxHeight MaxWidth -> 최대크기의 범위를 지정

   : MinHeight MinWidth -> 최소크기의 범위를 지정

   

   : HorizontalAlignment

   : Margin

   : Padding


   : FlowDirection  ->  컨텐츠의 흐름방향을 지정

                        (LeftToRight : 왼쪽->오른쪽)

                        (RightToLeft : 오른쪽->왼쪽)

   

   : Visibility -> 화면에 보이도록 할지, 숨길지를 결정

                   Collapse, Hidden, Visible

   : IsEnabled  -> True(활성화)/False(비활성화)   


2)

   : LayoutTransform

   : RenderTransform

            - MatrixTransform

            - RotateTransform

            - ScaleTransform

            - SkewTransform

            - TranslateTransform


3)

   : ZIndex -> 평면에서 계층을 이용할때




1. ActualHeight / ActualWidth / Visibility / IsEnabled  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<Window x:Class="WpfApp8.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp8"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="306,255,0,0" VerticalAlignment="Top" Height="106" Width="175" Click="Button_Click"/>
        <Label Name="lb1" Content="Label" HorizontalAlignment="Left" Margin="306,134,0,0" VerticalAlignment="Top"/>
        <Label Name="lb2" Content="Label" HorizontalAlignment="Left" Margin="306,206,0,0" VerticalAlignment="Top"/>
        <ComboBox Name="cb1" HorizontalAlignment="Left" Margin="306,61,0,0" VerticalAlignment="Top">
            <ComboBoxItem Content="item1"/>
            <ComboBoxItem Content="item2"/>
            <ComboBoxItem Content="item3"/>
        </ComboBox>
        <StackPanel Width="200" Height="100" Background="Tan" Margin="471,60,121,259">
            <Button Visibility="Collapsed" Height="40" Width="70">OK</Button>
            <Button Visibility="Visible" Height="40" Width="70">Cencle</Button>
        </StackPanel>
    </Grid>
</Window>
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
namespace WpfApp8
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            lb1.Content = string.Format($"ActualWidth : {cb1.ActualWidth.ToString()} / Width : {cb1.Width.ToString()}");
            lb2.Content = string.Format($"ActualHeight : {cb1.ActualHeight.ToString()} / Height : {cb1.Height.ToString()}");            
        }
    }
}
cs

====================================================

2. LayoutTransform / RenderTransform

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<Window x:Class="WpfApp9.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp9"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Button Grid.Row="0">OK</Button>
        <Button Grid.Row="1" Height="30">
            <TextBlock>
                <TextBlock.RenderTransform>
                    <RotateTransform Angle="180" CenterX="18" CenterY="8" />
                </TextBlock.RenderTransform>
                버튼2
            </TextBlock>
        </Button>
        <Button Grid.Row="2">
            <TextBlock>
                <TextBlock.LayoutTransform>
                    <ScaleTransform ScaleX="3" ScaleY="2"/>
                </TextBlock.LayoutTransform>
                버튼3
            </TextBlock>
        </Button>
        <Button Grid.Row="3">
            <TextBlock>
                <TextBlock.RenderTransform>
                    <ScaleTransform ScaleX="3" ScaleY="2"/>
                </TextBlock.RenderTransform>
                버튼4
            </TextBlock>
        </Button>
    </Grid>
</Window>
 
cs

====================================================

3. ZIndex 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<Window x:Class="WpfApp10.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp10"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Content="ZIndex1" HorizontalAlignment="Left" Margin="90,67,0,0" VerticalAlignment="Top" Width="90" Height="40" FontSize="20" Panel.ZIndex="3"/>
        <Button Content="ZIndex2" HorizontalAlignment="Left" Margin="110,90,0,0" VerticalAlignment="Top" Width="90" Height="40" FontSize="20" Panel.ZIndex="2"/>
        <Button Content="ZIndex3" HorizontalAlignment="Left" Margin="130,113,0,0" VerticalAlignment="Top" Width="90" Height="40" FontSize="20" Panel.ZIndex="0"/>
        <Button Content="ZIndex4" HorizontalAlignment="Left" Margin="150,136,0,0" VerticalAlignment="Top" Width="90" Height="40" FontSize="20" Panel.ZIndex="1"/>
    </Grid>
</Window>
 
cs


'프로그래밍' 카테고리의 다른 글

비디오 / form / 블록,라인  (0) 2019.03.27
이미지/사운드  (0) 2019.03.27
[WPF]WrapPanel  (0) 2019.02.01
[WPF]stackPanel  (0) 2019.02.01
[WPF]grid를 이용한 로그인화면  (0) 2019.01.31

댓글