첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ DockPanel 클래스를 사용해 자식 엘리먼트들의 공간 분할에 사용하는 방법을 보여준다.

TestProject.zip
0.01MB

▶ MainWindow.xaml

<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

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요