■ DockPanel 클래스를 사용해 자식 엘리먼트들의 공간 분할에 사용하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 |
<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"> </Window> |
▶ MainWindow.xaml.cs
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); DockPanel dockPanel = new DockPanel(); dockPanel.LastChildFill = true; TextBlock textBlock1 = new TextBlock(); textBlock1.Foreground = Brushes.Black; textBlock1.Text = "Dock = Top"; Border border1 = new Border(); border1.Height = 25; border1.BorderThickness = new Thickness(1); border1.BorderBrush = Brushes.Black; border1.Background = Brushes.SkyBlue; border1.Child = textBlock1; DockPanel.SetDock(border1, Dock.Top); TextBlock textBlock2 = new TextBlock(); textBlock2.Foreground = Brushes.Black; textBlock2.Text = "Dock = Top"; Border border2 = new Border(); border2.Height = 25; border2.BorderThickness = new Thickness(1); border2.BorderBrush = Brushes.Black; border2.Background = Brushes.SkyBlue; border2.Child = textBlock2; DockPanel.SetDock(border2, Dock.Top); TextBlock textBlock3 = new TextBlock(); textBlock3.Foreground = Brushes.Black; textBlock3.Text = "Dock = Bottom"; Border border3 = new Border(); border3.Height = 25; border3.BorderThickness = new Thickness(1); border3.BorderBrush = Brushes.Black; border3.Background = Brushes.LemonChiffon; border3.Child = textBlock3; DockPanel.SetDock(border3, Dock.Bottom); TextBlock textBlock4 = new TextBlock(); textBlock4.Foreground = Brushes.Black; textBlock4.Text = "Dock = Left"; Border border4 = new Border(); border4.Width = 200; border4.BorderThickness = new Thickness(1); border4.BorderBrush = Brushes.Black; border4.Background = Brushes.PaleGreen; border4.Child = textBlock4; DockPanel.SetDock(border4, Dock.Left); TextBlock textBlock5 = new TextBlock(); textBlock5.Foreground = Brushes.Black; textBlock5.Text = "This content will Fill the remaining space"; Border border5 = new Border(); border5.Background = Brushes.White; border5.BorderThickness = new Thickness(1); border5.BorderBrush = Brushes.Black; border5.Child = textBlock5; dockPanel.Children.Add(border1); dockPanel.Children.Add(border2); dockPanel.Children.Add(border3); dockPanel.Children.Add(border4); dockPanel.Children.Add(border5); Content = dockPanel; } #endregion } } |