■ ColumnDefinition 엘리먼트의 SharedSizeGroup 속성을 사용해 그리드 간 컬럼 크기를 공유하는 방법을 설정한다.
▶ MainWindow.xaml
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <DockPanel VerticalAlignment="Center" Margin="50" Grid.IsSharedSizeScope="True"> <Grid DockPanel.Dock="Top" Background="White"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="Number" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" SharedSizeGroup="Publisher" /> <ColumnDefinition Width="Auto" SharedSizeGroup="Price" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Border Grid.Column="0" Background="RoyalBlue" BorderBrush="Gray" BorderThickness="1" Padding="5"> <TextBlock HorizontalAlignment="Center" Foreground="White" Text="번호" /> </Border> <Border Grid.Column="1" Background="RoyalBlue" BorderThickness="1" BorderBrush="Gray" Padding="5"> <TextBlock HorizontalAlignment="Center" Foreground="White" Text="제목" /> </Border> <Border Grid.Column="2" Background="RoyalBlue" BorderThickness="1" BorderBrush="Gray" Padding="5"> <TextBlock HorizontalAlignment="Center" Foreground="White" Text="출판사" /> </Border> <Border Grid.Column="3" Background="RoyalBlue" BorderThickness="1" BorderBrush="Gray" Padding="5"> <TextBlock HorizontalAlignment="Center" Foreground="White" Text="가격" /> </Border> </Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="Number" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" SharedSizeGroup="Publisher"/> <ColumnDefinition Width="Auto" SharedSizeGroup="Price" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" Padding="5" Text="1" /> <TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Padding="5" Text="도서 1" /> <TextBlock Grid.Row="0" Grid.Column="2" HorizontalAlignment="Center" Padding="5" Text="A" /> <TextBlock Grid.Row="0" Grid.Column="3" HorizontalAlignment="Right" Padding="5" Text="25,000원" /> <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" Padding="5" Text="2" /> <TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Padding="5" Text="도서 2" /> <TextBlock Grid.Row="1" Grid.Column="2" HorizontalAlignment="Center" Padding="5" Text="B" /> <TextBlock Grid.Row="1" Grid.Column="3" HorizontalAlignment="Right" Padding="5" Text="35,000원" /> <TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" Padding="5" Text="3" /> <TextBlock Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Padding="5" Text="도서 3" /> <TextBlock Grid.Row="2" Grid.Column="2" HorizontalAlignment="Center" Padding="5" Text="C" /> <TextBlock Grid.Row="2" Grid.Column="3" HorizontalAlignment="Right" Padding="5" Text="15,000원" /> <TextBlock Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center" Padding="5" Text="4" /> <TextBlock Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" Padding="5" Text="도서 4" /> <TextBlock Grid.Row="3" Grid.Column="2" HorizontalAlignment="Center" Padding="5" Text="D" /> <TextBlock Grid.Row="3" Grid.Column="3" HorizontalAlignment="Right" Padding="5" Text="55,000원" /> </Grid> </DockPanel> </Window> |