728x90
반응형
728x170
■ DockPanel 클래스를 사용해 자식 엘리먼트들의 공간 분할에 사용하는 방법을 보여준다.
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Menu 엘리먼트 : 메뉴 스타일 설정하기 (0) | 2023.01.14 |
---|---|
[C#/WPF] GridViewRowPresenter 엘리먼트 : 데이터 표시하기 (0) | 2023.01.13 |
[C#/WPF] EventSetter 엘리먼트 : Event/Handler 속성을 사용해 ListBoxItem 객체를 마우스 더블 클릭시 처리하기 (0) | 2023.01.13 |
[C#/WPF] GridSplitter 엘리먼트 : Panel 엘리먼트의 ZIndex 첨부 속성을 사용해 그리드 스플리터 숨김 방지하기 (0) | 2023.01.12 |
[C#/WPF] GridSplitter 엘리먼트 : 그리드 행 크기 변경하기 (0) | 2023.01.12 |
[C#/WPF] Storyboard 엘리먼트 : 비동기 프로세스 동안 연속 애니메이션 표시하기 (0) | 2023.01.11 |
[C#/WPF] Style 엘리먼트 : TargetType 속성을 사용해 MenuItem 엘리먼트 스타일 설정하기 (0) | 2023.01.09 |
[C#/WPF] LengthConverter 클래스 : ConvertFromString 메소드를 사용해 문자열에서 길이 구하기 (0) | 2023.01.09 |
[C#/WPF] BulletDecorator 엘리먼트 사용하기 (0) | 2023.01.09 |
[C#/WPF] Border 클래스 : BorderThickness 속성을 변경시키는 애니메이션 만들기 (0) | 2023.01.09 |
댓글을 달아 주세요