첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

■ MDI 폼 사용하기

------------------------------------------------------------------------------------------------------------------------


TestSolution.zip



[TestLibrary 프로젝트]

 

MDILayout.cs

 

 

namespace TestLibrary

{

    /// <summary>

    /// MDI 레이아웃

    /// </summary>

    public enum MDILayout

    {

        /// <summary>

        /// 계단식

        /// </summary>

        Cascade,

 

        /// <summary>

        /// 수평 타일

        /// </summary>

        TileHorizontal,

 

        /// <summary>

        /// 수직 타일

        /// </summary>

        TileVertical,

 

        /// <summary>

        /// 아이콘 정렬

        /// </summary>

        ArrangeIcons

    }

}

 

 

ThemeType.cs

 

 

namespace TestLibrary

{

    /// <summary>

    /// 테마 타입

    /// </summary>

    public enum ThemeType

    {

        /// <summary>

        /// 일반

        /// </summary>

        Generic,

 

        /// <summary>

        /// 루나

        /// </summary>

        Luna,

 

        /// <summary>

        /// 에어로

        /// </summary>

        Aero

    }

}

 

 

ClosingEventArgs.cs

 

 

using System.Windows;

 

namespace TestLibrary

{

    /// <summary>

    /// 종료시 이벤트 인자

    /// </summary>

    public class ClosingEventArgs : RoutedEventArgs

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 취소 여부 - Cancel

 

        /// <summary>

        /// 취소 여부

        public bool Cancel { get; set; }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - ClosingEventArgs(routedEvent)

 

        /// <summary>

        /// 생성자

        /// </summary>

        /// <param name="routedEvent">라우팅 이벤트</param>

        public ClosingEventArgs(RoutedEvent routedEvent) : base(routedEvent)

        {

        }

 

        #endregion

    }

}

 

 

Aero.xaml

 

 

<ResourceDictionary

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="clr-namespace:TestLibrary;assembly=TestLibrary">

    <SolidColorBrush x:Key="NormalBorderBrushKey"

        Color="#ff6a7a93" />

    <LinearGradientBrush x:Key="NormalSubBorderBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffc3d4e7" />

        <GradientStop Offset="0.5" Color="#ffbed3e8" />

        <GradientStop Offset="0.5" Color="#ff98b1cc" />

        <GradientStop Offset="1.0" Color="#ffb7d0e9" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalSubBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffdfe8f2" />

        <GradientStop Offset="0.5" Color="#ffdde7f3" />

        <GradientStop Offset="0.5" Color="#ffc8d5e4" />

        <GradientStop Offset="1.0" Color="#ffd9e7f4" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalDownBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ff7f9aac" />

        <GradientStop Offset="0.5" Color="#ff5d778c" />

        <GradientStop Offset="0.5" Color="#ff203b52" />

        <GradientStop Offset="1.0" Color="#ff27c9c8" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalDownBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffacbec9" />

        <GradientStop Offset="0.5" Color="#ff90a2b1" />

        <GradientStop Offset="0.5" Color="#ff667888" />

        <GradientStop Offset="1.0" Color="#ff67e6e4" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalUnfocusedBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0" Color="#ffbdcbda" />

        <GradientStop Offset="1" Color="#ffcedceb" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalUnfocusedBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0" Color="#FFD1DBE5" />

        <GradientStop Offset="1" Color="#FFD1DBE5" />

    </LinearGradientBrush>

    <SolidColorBrush x:Key="NormalUnfocusedSubBorderBrushKey"

        Color="#ff838ea8" />

    <LinearGradientBrush x:Key="NormalOverBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffaad5f3" />

        <GradientStop Offset="0.5" Color="#ff81c0ea" />

        <GradientStop Offset="0.5" Color="#ff2d73a3" />

        <GradientStop Offset="1.0" Color="#ff24c6eb" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalOverBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffd6ebfa" />

        <GradientStop Offset="0.5" Color="#ffbbddf3" />

        <GradientStop Offset="0.5" Color="#ff8eb4ce" />

        <GradientStop Offset="1.0" Color="#ff85eff9" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalDisabledBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0"   Color="#FFB5CAE1" />

        <GradientStop Offset="1"   Color="#FFB7D0E9" />

        <GradientStop Offset="0.5" Color="#FFB5CCE5" />

        <GradientStop Offset="0.5" Color="#FFA3BCD7" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalDisabledBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0"   Color="#ffc2d3e6" />

        <GradientStop Offset="1"   Color="#ffc9ddf0" />

        <GradientStop Offset="0.5" Color="#ffc4d7ea" />

        <GradientStop Offset="0.5" Color="#ffbbcee3" />

    </LinearGradientBrush>

    <SolidColorBrush x:Key="NormalDisabledSubBorderBrushKey"

        Color="#ff859bb5" />

    <LinearGradientBrush x:Key="NormalDisabledFocusedBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0" Color="#ffc4d2e0" />

        <GradientStop Offset="1" Color="#ffd5e3f2" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="NormalDisabledFocusedBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0" Color="#ffd3dee9" />

        <GradientStop Offset="1" Color="#ffe2edf7" />

    </LinearGradientBrush>

    <Style x:Key="WindowButtonStyleKey" TargetType="{x:Type Button}">

        <Setter Property="SnapsToDevicePixels" Value="True" />

        <Setter Property="IsTabStop"           Value="False" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type Button}">

                    <Border Name="BaseBorder"

                        CornerRadius="2"

                        BorderThickness="1"

                        BorderBrush="{StaticResource NormalBorderBrushKey}">

                        <Border Name="Border"

                            CornerRadius="2"

                            BorderThickness="1"

                            BorderBrush="{StaticResource NormalSubBorderBrushKey}"

                            Background="{StaticResource NormalSubBorderBackgroundBrushKey}">

                            <ContentPresenter Content="{TemplateBinding Content}" />

                        </Border>

                    </Border>

                    <ControlTemplate.Triggers>

                        <Trigger Property="IsPressed" Value="True">

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource NormalDownBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource NormalDownBorderBrushKey}" />

                        </Trigger>

                        <Trigger Property="Tag" Value="0">

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource NormalUnfocusedBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource NormalUnfocusedBorderBrushKey}" />

                            <Setter

                                TargetName="BaseBorder"

                                Property="BorderBrush"

                                Value="{StaticResource NormalUnfocusedSubBorderBrushKey}" />

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="IsMouseOver" Value="True" />

                                <Condition Property="IsPressed"   Value="False" />

                            </MultiTrigger.Conditions>

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource NormalOverBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource NormalOverBorderBrushKey}" />

                        </MultiTrigger>

                        <Trigger Property="IsEnabled" Value="False">

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource NormalDisabledBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource NormalDisabledBorderBrushKey}" />

                            <Setter

                                TargetName="BaseBorder"

                                Property="BorderBrush"

                                Value="{StaticResource NormalDisabledSubBorderBrushKey}" />

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="Tag"       Value="0"     />

                                <Condition Property="IsEnabled" Value="False" />

                            </MultiTrigger.Conditions>

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource NormalDisabledFocusedBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource NormalDisabledFocusedBorderBrushKey}" />

                        </MultiTrigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

    <SolidColorBrush x:Key="CloseBorderBrushKey"

        Color="#ff431422" />

    <LinearGradientBrush x:Key="CloseSubBorderBackgroundKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffe9a99c" />

        <GradientStop Offset="0.5" Color="#ffdf9487" />

        <GradientStop Offset="0.5" Color="#ffb8432c" />

        <GradientStop Offset="1.0" Color="#ffd27e6f" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="CloseSubBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#fff4d3cc" />

        <GradientStop Offset="0.5" Color="#ffedc4bd" />

        <GradientStop Offset="0.5" Color="#ffd99a8e" />

        <GradientStop Offset="1.0" Color="#ffecc6c0" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="CloseDownBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffcfa38b" />

        <GradientStop Offset="0.5" Color="#ffbe836a" />

        <GradientStop Offset="0.5" Color="#ff831800" />

        <GradientStop Offset="1.0" Color="#ffc4954c" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="CloseDownBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#ffe6cfc3" />

        <GradientStop Offset="0.5" Color="#ffccb0a5" />

        <GradientStop Offset="0.5" Color="#ffb28176" />

        <GradientStop Offset="1.0" Color="#fff5ec6a" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="CloseUnfocusedBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0" Color="#ffbdcbda" />

        <GradientStop Offset="1" Color="#ffcedceb" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="CloseUnfocusedBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0" Color="#ffd1dbe5" />

        <GradientStop Offset="1" Color="#ffd1dbe5" />

    </LinearGradientBrush>

    <SolidColorBrush x:Key="CloseUnfocusedSubBorderBrushKey"

        Color="#ff838ea8" />

    <LinearGradientBrush x:Key="CloseOverBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#FFE9A99C" />

        <GradientStop Offset="0.5" Color="#FFFAA99A" />

        <GradientStop Offset="0.5" Color="#FFD22302" />

        <GradientStop Offset="1.0" Color="#FFE5934D" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="CloseOverBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#fffde4e0" />

        <GradientStop Offset="0.5" Color="#fffde4e0" />

        <GradientStop Offset="0.5" Color="#ffe78977" />

        <GradientStop Offset="1.0" Color="#fffaee6b" />

    </LinearGradientBrush>

    <Style x:Key="CloseButtonStyleKey" TargetType="{x:Type Button}">

        <Setter Property="SnapsToDevicePixels" Value="True" />

        <Setter Property="IsTabStop"           Value="False" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type Button}">

                    <Border Name="BaseBorder"

                        CornerRadius="2"

                        BorderThickness="1"

                        BorderBrush="{StaticResource CloseBorderBrushKey}">

                        <Border Name="Border"

                            CornerRadius="2"

                            BorderThickness="1"

                            BorderBrush="{StaticResource CloseSubBorderBrushKey}"

                            Background="{StaticResource CloseSubBorderBackgroundKey}">

                            <Image

                                HorizontalAlignment="Center"

                                VerticalAlignment="Center"

                                Width="11"

                                Height="9"

                                Source="/TestLibrary;component/THEMES/AERO/Close.png" />

                        </Border>

                    </Border>

                    <ControlTemplate.Triggers>

                        <Trigger Property="IsPressed" Value="True">

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource CloseDownBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource CloseDownBorderBrushKey}" />

                        </Trigger>

                        <Trigger Property="Tag" Value="0">

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource CloseUnfocusedBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource CloseUnfocusedBorderBrushKey}" />

                            <Setter

                                TargetName="BaseBorder"

                                Property="BorderBrush"

                                Value="{StaticResource CloseUnfocusedSubBorderBrushKey}" />

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="IsMouseOver" Value="True" />

                                <Condition Property="IsPressed"   Value="False" />

                            </MultiTrigger.Conditions>

                            <Setter

                                TargetName="Border"

                                Property="Background"

                                Value="{StaticResource CloseOverBackgroundBrushKey}" />

                            <Setter

                                TargetName="Border"

                                Property="BorderBrush"

                                Value="{StaticResource CloseOverBorderBrushKey}" />

                        </MultiTrigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

    <SolidColorBrush x:Key="MaximizedBaseBorderBrushKeyKey"

        Color="#ff98a6b4" />

    <SolidColorBrush x:Key="MaximizedDownBaseBorderBrushKeyKey"

        Color="#ff6f7d8b" />

    <LinearGradientBrush x:Key="MaximizedSubBorderBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0"    Color="#fff6faff" />

        <GradientStop Offset="0.15" Color="#fff6faff" />

        <GradientStop Offset="0.15" Color="#ffe9f3ff" />

        <GradientStop Offset="1"    Color="#ffe3f1ff" />

    </LinearGradientBrush>

    <SolidColorBrush x:Key="MaximizedDownSubBorderBrushKey"

        Color="#d0deec" />

    <LinearGradientBrush x:Key="MaximizedBorderBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0"    Color="#fff1f8ff" />

        <GradientStop Offset="0.15" Color="#fff1f8ff" />

        <GradientStop Offset="0.15" Color="#ffdeecfa" />

        <GradientStop Offset="1"    Color="#ffdae8f6" />

    </LinearGradientBrush>

    <Style x:Key="MaximizedButtonStyleKey" TargetType="{x:Type Button}">

        <Setter Property="Width"     Value="18"    />

        <Setter Property="Height"    Value="18"    />

        <Setter Property="IsTabStop" Value="False" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type Button}">

                    <Border Name="BaseBorder"

                        BorderThickness="1"

                        BorderBrush="{StaticResource MaximizedBaseBorderBrushKeyKey}">

                        <Border Name="SubBorder"

                            BorderThickness="1 1 1 0"

                            BorderBrush="{StaticResource MaximizedSubBorderBrushKey}">

                            <Border Name="Border"

                                Background="{StaticResource MaximizedBorderBackgroundBrushKey}">

                                <ContentPresenter

                                    Margin="0 2 0 0"

                                    Content="{TemplateBinding Content}" />

                            </Border>

                        </Border>

                    </Border>

                    <ControlTemplate.Triggers>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="IsPressed" Value="True" />

                                <Condition Property="IsEnabled" Value="True" />

                            </MultiTrigger.Conditions>

                            <Setter

                                TargetName="BaseBorder"

                                Property="BorderBrush"

                                Value="{StaticResource MaximizedDownBaseBorderBrushKeyKey}" />

                            <Setter

                                TargetName="SubBorder"

                                Property="BorderBrush"

                                Value="{StaticResource MaximizedDownSubBorderBrushKey}" />

                        </MultiTrigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

    <SolidColorBrush x:Key="BackBorderBackgroundBrushKey"

        Color="#ffbbd2eb" />

    <SolidColorBrush x:Key="BackBorderBrushKey"

        Color="Black" />

    <LinearGradientBrush x:Key="DarkenBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#20000000" />

        <GradientStop Offset="1.0" Color="#00000000" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="HighlightBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#00ffffff" />

        <GradientStop Offset="1.0" Color="#7dffffff" />

    </LinearGradientBrush>

    <SolidColorBrush x:Key="NearBorderBrushKey"

        Color="White" />

    <SolidColorBrush x:Key="FarBorderBrushKey"

        Color="#ff3fcef2" />

    <SolidColorBrush x:Key="ChildBackgroundKey"

        Color="#fff0f0f0" />

    <BitmapImage x:Key="RestoreImageKey"

        UriSource="/TestLibrary;component/THEMES/AERO/Restore.png" />

    <SolidColorBrush x:Key="BackBorderMaximizedBrushKey"

        Color="#ff4a5764" />

    <LinearGradientBrush x:Key="DarkenMaximizedBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#fffefeff" />

        <GradientStop Offset="0.3" Color="#ffe5eaf5" />

        <GradientStop Offset="0.3" Color="#ffd4dbed" />

        <GradientStop Offset="1.0" Color="#ffe1e6f6" />

    </LinearGradientBrush>

    <SolidColorBrush x:Key="DarkenMaximizedBorderBrushKey"

        Color="#fffb6bcc" />

    <SolidColorBrush x:Key="ContentMaximizedBorderBrushKey"

        Color="#ffa0a0a0" />

    <BitmapImage x:Key="MaximizedMinimizeImageKey"

        UriSource="/TestLibrary;component/THEMES/AERO/MaximizedMinimize.png" />

    <BitmapImage x:Key="MaximizedRestoreImageKey"

        UriSource="/TestLibrary;component/THEMES/AERO/MaximizedRestore.png" />

    <BitmapImage x:Key="MaximizedCloseImageKey"

        UriSource="/TestLibrary;component/THEMES/AERO/MaximizedClose.png" />

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverterKey" />

    <Style TargetType="{x:Type local:MDIChild}">

        <Setter Property="Width"      Value="300" />

        <Setter Property="Height"     Value="300" />

        <Setter Property="MinWidth"   Value="150" />

        <Setter Property="MinHeight" Value="35" />

        <Setter Property="Background" Value="{StaticResource ChildBackgroundKey}" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type local:MDIChild}">

                    <Border Name="BaseBorder"

                        CornerRadius="5 5 0 0"

                        BorderThickness="1"

                        BorderBrush="{StaticResource BackBorderBrushKey}"

                        Background="{StaticResource BackBorderBackgroundBrushKey}">

                        <Grid>

                            <Border Name="DarkenBackground"

                                VerticalAlignment="Top"

                                Height="28"

                                CornerRadius="5 5 0 0"

                                Background="{StaticResource DarkenBackgroundBrushKey}" />

                            <Border Name="HighlightBackground"

                                VerticalAlignment="Top"

                                Height="134"

                                CornerRadius="5 5 0 0"

                                Background="{StaticResource HighlightBackgroundBrushKey}" />

                            <Thumb Name="DragThumb"

                                VerticalAlignment="Top"

                                Height="30"

                                Opacity="0" />

                            <StackPanel Name="ButtonStackPanel"

                                HorizontalAlignment="Right"

                                VerticalAlignment="Top"

                                Margin="0 9 8 0"

                                Orientation="Horizontal">

                                <Button Name="MinimizeButton"

                                    Margin="0 0 2 0"

                                    Width="31"

                                    Height="17"

                                    RenderOptions.BitmapScalingMode="NearestNeighbor"

                                    Style="{DynamicResource WindowButtonStyleKey}">

                                    <Image

                                        Margin="0 3 0 0"

                                        Width="11"

                                        Height="5"

                                        Source="/TestLibrary;component/THEMES/AERO/Minimize.png" />

                                </Button>

                                <Button Name="MaximizeButton"

                                    Style="{DynamicResource WindowButtonStyleKey}"

                                    Margin="0 0 2 0"

                                    Width="31"

                                    Height="17">

                                    <Image

                                        Width="11"

                                        Height="9"

                                        Source="/TestLibrary;component/THEMES/AERO/Maximize.png" />

                                </Button>

                                <Button Name="CloseButton"

                                    Style="{DynamicResource CloseButtonStyleKey}"

                                    Width="31"

                                    Height="17" />

                            </StackPanel>

                            <Grid Name="HeaderContent"

                                VerticalAlignment="Top"

                                Margin="6 0 109 0"

                                Height="28"

                                IsHitTestVisible="False">

                                <Grid.ColumnDefinitions>

                                    <ColumnDefinition Width="Auto" />

                                    <ColumnDefinition              />

                                </Grid.ColumnDefinitions>

                                <Image Name="IconImage"

                                    Margin="2 6 0 0"

                                    Width="16"

                                    Height="16"

                                    Stretch="Fill"

                                    RenderOptions.BitmapScalingMode="NearestNeighbor"

                                    Source="{TemplateBinding Icon}"

                                    Visibility="{TemplateBinding ShowIcon, Converter={StaticResource BooleanToVisibilityConverterKey}}" />

                                <TextBlock Name="Header" Grid.Column="1"

                                    Margin="4 9 0 0"

                                    TextTrimming="CharacterEllipsis"

                                    TextWrapping="NoWrap"

                                    Text="{TemplateBinding Title}" />

                            </Grid>

                            <Border Name="ContentBorder"

                                Margin="6 30 6 6"

                                BorderBrush="{TemplateBinding BorderBrush}"

                                BorderThickness="{TemplateBinding BorderThickness}"

                                Background="{TemplateBinding Background}">

                                <ContentControl Content="{TemplateBinding Content}" />

                            </Border>

                            <Rectangle Name="LeftBorder"

                                HorizontalAlignment="Left"

                                Width="1"

                                RadiusX="9"

                                RadiusY="9"

                                Fill="{StaticResource NearBorderBrushKey}" />

                            <Rectangle Name="TopBorder"

                                VerticalAlignment="Top"

                                Height="1"

                                RadiusX="9"

                                RadiusY="9"

                                Fill="{StaticResource NearBorderBrushKey}" />

                            <Rectangle Name="RightBorder"

                                HorizontalAlignment="Right"

                                Width="1"

                                RadiusX="9"

                                RadiusY="9"

                                Fill="{StaticResource FarBorderBrushKey}" />

                            <Rectangle Name="BottomBorder"

                                VerticalAlignment="Bottom"

                                Height="1"

                                RadiusX="9"

                                RadiusY="9"

                                Fill="{StaticResource FarBorderBrushKey}" />

                            <Thumb Name="ResizeLeft"

                                HorizontalAlignment="Left"

                                Margin="0 6 0 6"

                                Width="6"

                                Opacity="0"

                                Cursor="SizeWE"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                            <Thumb Name="ResizeTop"

                                VerticalAlignment="Top"

                                Margin="6 0 6 0"

                                Height="4"

                                Opacity="0"

                                Cursor="SizeNS"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                            <Thumb Name="ResizeRight"

                                HorizontalAlignment="Right"

                                Margin="0 6 0 6"

                                Width="6"

                                Opacity="0"

                                Cursor="SizeWE"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                            <Thumb Name="ResizeBottom"

                                VerticalAlignment="Bottom"

                                Margin="6 0 6 0"

                                Height="6"

                                Opacity="0"

                                Cursor="SizeNS"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                            <Thumb Name="ResizeTopLeft"

                                HorizontalAlignment="Left"

                                VerticalAlignment="Top"

                                Width="6"

                                Height="6"

                                Opacity="0"

                                Cursor="SizeNWSE"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                            <Thumb Name="ResizeTopRight"

                                HorizontalAlignment="Right"

                                VerticalAlignment="Top"

                                Width="6"

                                Height="6"

                                Opacity="0"

                                Cursor="SizeNESW"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                            <Thumb Name="ResizeBottomRight"

                                HorizontalAlignment="Right"

                                VerticalAlignment="Bottom"

                                Width="6"

                                Height="6"

                                Opacity="0"

                                Cursor="SizeNWSE"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                            <Thumb Name="ResizeBottomLeft"

                                HorizontalAlignment="Left"

                                VerticalAlignment="Bottom"

                                Width="6"

                                Height="6"

                                Opacity="0"

                                Cursor="SizeNESW"

                                IsHitTestVisible="{TemplateBinding Resizable}" />

                        </Grid>

                    </Border>

                    <ControlTemplate.Triggers>

                        <Trigger Property="Focused" Value="False">

                            <Setter TargetName="BaseBorder"          Property="Background" Value="#d7e4f2" />

                            <Setter TargetName="HighlightBackground" Property="Opacity"    Value="0"       />

                            <Setter TargetName="DarkenBackground"    Property="Opacity"    Value="0.5"     />

                            <Setter TargetName="LeftBorder"          Property="Opacity"    Value="0.75"    />

                            <Setter TargetName="TopBorder"           Property="Opacity"    Value="0.75"    />

                            <Setter TargetName="RightBorder"         Property="Opacity"    Value="0"       />

                            <Setter TargetName="BottomBorder"        Property="Opacity"    Value="0"       />

                            <Setter TargetName="CloseButton"         Property="Tag"        Value="0"       />

                            <Setter TargetName="MaximizeButton"      Property="Tag"        Value="0"       />

                            <Setter TargetName="MinimizeButton"      Property="Tag"        Value="0"       />

                        </Trigger>

                        <Trigger SourceName="IconImage" Property="Source" Value="{x:Null}">

                            <Setter TargetName="IconImage" Property="Width" Value="0" />

                            <Setter TargetName="IconImage" Property="Margin" Value="0" />

                        </Trigger>

                        <Trigger Property="WindowState" Value="Minimized">

                            <Setter Property="MinWidth" Value="160"   />

                            <Setter Property="MinHeight" Value="29"    />

                            <Setter Property="Width"     Value="160"   />

                            <Setter Property="Height"    Value="29"    />

                            <Setter Property="Resizable" Value="False" />

                            <Setter TargetName="ButtonStackPanel" Property="Margin" Value="0 5 5 0" />

                            <Setter TargetName="IconImage"        Property="Margin" Value="2 0 0 0" />

                            <Setter TargetName="Header"           Property="Margin" Value="4 6 0 0" />

                            <Setter TargetName="MinimizeButton"   Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Button

                                            Style="{DynamicResource WindowButtonStyleKey}"

                                            Width="31"

                                            Height="17">

                                            <Image

                                                Width="12"

                                                Height="11"

                                                Source="{StaticResource RestoreImageKey}" />

                                        </Button>

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="WindowState" Value="Minimized" />

                                <Condition Property="Focused"     Value="False"     />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Button

                                            Style="{DynamicResource WindowButtonStyleKey}"

                                            Width="31"

                                            Height="17"

                                            Tag="0">

                                            <Image

                                                Width="12"

                                                Height="11"

                                                Source="{StaticResource RestoreImageKey}" />

                                        </Button>

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <Trigger Property="WindowState" Value="Maximized">

                            <Setter Property="Resizable" Value="False" />

                            <Setter

                                TargetName="BaseBorder"

                                Property="BorderThickness"

                                Value="0,1,0,0" />

                            <Setter

                                TargetName="BaseBorder"

                                Property="BorderBrush"

                                Value="{StaticResource BackBorderMaximizedBrushKey}" />

                            <Setter

                                TargetName="BaseBorder"

                                Property="CornerRadius"

                                Value="0" />

                            <Setter

                                TargetName="DarkenBackground"

                                Property="Background"

                                Value="{StaticResource DarkenMaximizedBrushKey}" />

                            <Setter

                                TargetName="DarkenBackground"

                                Property="BorderBrush"

                                Value="{StaticResource DarkenMaximizedBorderBrushKey}" />

                            <Setter

                                TargetName="DarkenBackground"

                                Property="BorderThickness"

                                Value="0 0 0 1" />

                            <Setter

                                TargetName="DarkenBackground"

                                Property="CornerRadius"

                                Value="0" />

                            <Setter

                                TargetName="HighlightBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="ContentBorder"

                                Property="BorderThickness"

                                Value="1" />

                            <Setter

                                TargetName="ContentBorder"

                                Property="BorderBrush"

                                Value="{StaticResource ContentMaximizedBorderBrushKey}" />

                            <Setter

                                TargetName="ContentBorder"

                                Property="Margin"

                                Value="0 0 0 0" />

                            <Setter

                                TargetName="HeaderContent"

                                Property="Height"

                                Value="20" />

                            <Setter

                                TargetName="LeftBorder"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="TopBorder"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="RightBorder"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="BottomBorder"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="Header"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="IconImage"

                                Property="Margin"

                                Value="2 0 0 0" />

                            <Setter

                                TargetName="MinimizeButton"

                                Property="Margin"

                                Value="20 1 1 1" />

                            <Setter

                                TargetName="MaximizeButton"

                                Property="Margin"

                                Value="1" />

                            <Setter

                                TargetName="CloseButton"

                                Property="Margin"

                                Value="1" />

                            <Setter

                                TargetName="MinimizeButton"

                                Property="Width"

                                Value="18" />

                            <Setter

                                TargetName="MaximizeButton"

                                Property="Width"

                                Value="18" />

                            <Setter

                                TargetName="CloseButton"

                                Property="Width"

                                Value="18" />

                            <Setter

                                TargetName="MinimizeButton"

                                Property="Height"

                                Value="18" />

                            <Setter

                                TargetName="MaximizeButton"

                                Property="Height"

                                Value="18" />

                            <Setter

                                TargetName="CloseButton"

                                Property="Height"

                                Value="18" />

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Button Style="{DynamicResource MaximizedButtonStyleKey}">

                                            <Image

                                                Width="14"

                                                Height="13"

                                                Source="{StaticResource MaximizedMinimizeImageKey}" />

                                        </Button>

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                            <Setter TargetName="MaximizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Button Style="{DynamicResource MaximizedButtonStyleKey}">

                                            <Image

                                                Width="14"

                                                Height="13"

                                                Source="{StaticResource MaximizedRestoreImageKey}" />

                                        </Button>

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                            <Setter TargetName="CloseButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Button Style="{DynamicResource MaximizedButtonStyleKey}">

                                            <Image

                                                Width="14"

                                                Height="13"

                                                Source="{StaticResource MaximizedCloseImageKey}" />

                                        </Button>

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

</ResourceDictionary>

 

 

Generic.xaml

 

 

<ResourceDictionary

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="clr-namespace:TestLibrary">

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverterKey" />

    <SolidColorBrush x:Key="BaseBackgroundBrushKey"

        Color="White" />

    <SolidColorBrush x:Key="BaseBorderBrushKey"

        Color="#ffbdbdbd" />

    <SolidColorBrush x:Key="TitleForegroundBrushKey"

        Color="#ffbebebe" />

    <SolidColorBrush x:Key="InnerBorderBrushKey"

        Color="#fff6f6f6" />

    <Style TargetType="{x:Type local:MDIChild}">

        <Setter Property="Width" Value="300" />

        <Setter Property="Height" Value="300" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type local:MDIChild}">

                    <Border

                        BorderThickness="1"

                        BorderBrush="{StaticResource BaseBorderBrushKey}"

                        Background="{StaticResource BaseBackgroundBrushKey}">

                        <Border.BitmapEffect>

                            <OuterGlowBitmapEffect

                                GlowColor="Black"

                                GlowSize="5"

                                Opacity="0.2" />

                        </Border.BitmapEffect>

                        <Grid>

                            <TextBlock

                                Margin="10 0 0 0"

                                Foreground="{StaticResource TitleForegroundBrushKey}"

                                Text="{TemplateBinding Title}" />

                            <Border

                                Margin="10 26 10 10"

                                BorderThickness="1"

                                BorderBrush="{StaticResource InnerBorderBrushKey}"

                                Background="{TemplateBinding Background}">

                                <ContentControl Content="{TemplateBinding Content}" />

                            </Border>

                        </Grid>

                    </Border>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

</ResourceDictionary>

 

 

Luna.xaml

 

 

<ResourceDictionary

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="clr-namespace:TestLibrary;assembly=TestLibrary">

    <Style x:Key="WindowButtonStyleKey" TargetType="{x:Type Button}">

        <Setter Property="SnapsToDevicePixels" Value="True" />

        <Setter Property="IsTabStop"           Value="False" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type Button}">

                    <ContentPresenter Content="{TemplateBinding Content}" />

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

    <SolidColorBrush x:Key="BackBorderBackgroundBrushKey"

        Color="#bbd2eb" />

    <SolidColorBrush x:Key="BackBorderBrushKey"

        Color="Black" />

    <LinearGradientBrush x:Key="DarkenBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#20000000" />

        <GradientStop Offset="1.0" Color="#00000000" />

    </LinearGradientBrush>

    <LinearGradientBrush x:Key="HighlightBackgroundBrushKey"

        EndPoint="0 1">

        <GradientStop Offset="0.0" Color="#00ffffff" />

        <GradientStop Offset="1.0" Color="#7dffffff" />

    </LinearGradientBrush>

    <SolidColorBrush x:Key="NearBorderBrushKey"

        Color="White" />

    <SolidColorBrush x:Key="FarBorderBrushKey"

        Color="#ff3fcef2" />

    <BitmapImage x:Key="TopLeftFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/TopLeftFocused.png" />

    <BitmapImage x:Key="TopLeftUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/TopLeftUnfocused.png" />

    <BitmapImage x:Key="TopMiddleFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/TopMiddleFocused.png" />

    <BitmapImage x:Key="TopMiddleUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/TopMiddleUnfocused.png" />

    <BitmapImage x:Key="TopRightFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/TopRightFocused.png" />

    <BitmapImage x:Key="TopRightUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/TopRightUnfocused.png" />

    <BitmapImage x:Key="LeftFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/LeftFocused.png" />

    <BitmapImage x:Key="LeftUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/LeftUnfocused.png" />

    <BitmapImage x:Key="RightFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/RightFocused.png" />

    <BitmapImage x:Key="RightUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/RightUnfocused.png" />

    <BitmapImage x:Key="BottomLeftFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/BottomLeftFocused.png" />

    <BitmapImage x:Key="BottomLeftUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/BottomLeftUnfocused.png" />

    <BitmapImage x:Key="BottomMiddleFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/BottomMiddleFocused.png" />

    <BitmapImage x:Key="BottomMiddleUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/BottomMiddleUnfocused.png" />

    <BitmapImage x:Key="BottomRightFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/BottomRightFocused.png" />

    <BitmapImage x:Key="BottomRightUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/BottomRightUnfocused.png" />

    <BitmapImage x:Key="CloseNormalFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/CloseNormalFocused.png" />

    <BitmapImage x:Key="CloseNormalUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/CloseNormalUnfocused.png" />

    <BitmapImage x:Key="CloseOver"

        UriSource="/TestLibrary;component/THEMES/LUNA/CloseOver.png" />

    <BitmapImage x:Key="CloseDown"

        UriSource="/TestLibrary;component/THEMES/LUNA/CloseDown.png" />

    <BitmapImage x:Key="MaximizeNormalFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizeNormalFocused.png" />

    <BitmapImage x:Key="MaximizeNormalUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizeNormalUnfocused.png" />

    <BitmapImage x:Key="MaximizeDisabledFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizeDisabledFocused.png" />

    <BitmapImage x:Key="MaximizeDisabledUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizeDisabledUnfocused.png" />

    <BitmapImage x:Key="MaximizeOver"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizeOver.png" />

    <BitmapImage x:Key="MaximizeDown"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizeDown.png" />

    <BitmapImage x:Key="MinimizeNormalFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizeNormalFocused.png" />

    <BitmapImage x:Key="MinimizeNormalUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizeNormalUnfocused.png" />

    <BitmapImage x:Key="MinimizeDisabledFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizeDisabledFocused.png" />

    <BitmapImage x:Key="MinimizeDisabledUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizeDisabledUnfocused.png" />

    <BitmapImage x:Key="MinimizeOver"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizeOver.png" />

    <BitmapImage x:Key="MinimizeDown"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizeDown.png" />

    <BitmapImage x:Key="RestoreNormalFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/RestoreNormalFocused.png" />

    <BitmapImage x:Key="RestoreNormalUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/RestoreNormalUnfocused.png" />

    <BitmapImage x:Key="RestoreOver"

        UriSource="/TestLibrary;component/THEMES/LUNA/RestoreOver.png" />

    <BitmapImage x:Key="RestoreDown"

        UriSource="/TestLibrary;component/THEMES/LUNA/RestoreDown.png" />

    <SolidColorBrush x:Key="ChildBackgroundKeyBrushKey"

        Color="#ffefebde" />

    <BitmapImage x:Key="MinimizedTopLeftFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizedLeftFocused.png" />

    <BitmapImage x:Key="MinimizedTopMiddleFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizedMiddleFocused.png" />

    <BitmapImage x:Key="MinimizedTopRightFocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizedRightFocused.png" />

    <BitmapImage x:Key="MinimizedTopLeftUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizedLeftUnfocused.png" />

    <BitmapImage x:Key="MinimizedTopMiddleUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizedMiddleUnfocused.png" />

    <BitmapImage x:Key="MinimizedTopRightUnfocused"

        UriSource="/TestLibrary;component/THEMES/LUNA/MinimizedRightUnfocused.png" />

    <BitmapImage x:Key="MaximizedMinimizeImageKey"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizedMinimize.png" />

    <BitmapImage x:Key="MaximizedRestoreImageKey"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizedRestore.png" />

    <BitmapImage x:Key="MaximizedCloseImageKey"

        UriSource="/TestLibrary;component/THEMES/LUNA/MaximizedClose.png" />

    <SolidColorBrush x:Key="ContentHostBackgroundBrushKey"

        Color="#ffadaa9c" />

    <SolidColorBrush x:Key="TopBackgroundBrushKey"

        Color="#ffefebde" />

    <SolidColorBrush x:Key="TopBackgroundBorderBrushKey"

        Color="White" />

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverterKey" />

    <Style TargetType="{x:Type local:MDIChild}">

        <Setter Property="Width"      Value="300" />

        <Setter Property="Height"     Value="300" />

        <Setter Property="MinWidth"   Value="150" />

        <Setter Property="MinHeight" Value="31" />

        <Setter Property="Background" Value="{StaticResource ChildBackgroundKeyBrushKey}" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type local:MDIChild}">

                    <Grid>

                        <Border Name="TopBackground"

                            VerticalAlignment="Top"

                            Height="21"

                            Background="Transparent" />

                        <Image Name="TopLeftBackground"

                            HorizontalAlignment="Left"

                            VerticalAlignment="Top"

                            Width="33"

                            Height="29"

                            Source="{StaticResource TopLeftFocused}" />

                        <Image Name="TopMiddleBackground"

                            Margin="33 0 33 0"

                            HorizontalAlignment="Stretch"

                            VerticalAlignment="Top"

                            Height="29"

                            Stretch="Fill"

                            Source="{StaticResource TopMiddleFocused}" />

                        <Image Name="TopRightBackground"

                            HorizontalAlignment="Right"

                            VerticalAlignment="Top"

                            Width="33"

                            Height="29"

                            Source="{StaticResource TopRightFocused}" />

                        <Image Name="LeftBackground"

                            Margin="0 29 0 5"

                            HorizontalAlignment="Left"

                            VerticalAlignment="Stretch"

                            Width="5"

                            Stretch="Fill"

                            Source="{StaticResource LeftFocused}" />

                        <Image Name="RightBackground"

                            Margin="0 29 0 5"

                            HorizontalAlignment="Right"

                            VerticalAlignment="Stretch"

                            Width="5"

                            Stretch="Fill"

                            Source="{StaticResource RightFocused}" />

                        <Image Name="BottomLeftBackground"

                            HorizontalAlignment="Left"

                            VerticalAlignment="Bottom"

                            Width="24"

                            Height="5"

                            Source="{StaticResource BottomLeftFocused}" />

                        <Image Name="BottomMiddleBackground"

                            Margin="24 0 24 0"

                            HorizontalAlignment="Stretch"

                            VerticalAlignment="Bottom"

                            Height="5"

                            Stretch="Fill"

                            Source="{StaticResource BottomMiddleFocused}" />

                        <Image Name="BottomRightBackground"

                            Width="24"

                            Height="5"

                            HorizontalAlignment="Right"

                            VerticalAlignment="Bottom"

                            Source="{StaticResource BottomRightFocused}" />

                        <Thumb Name="DragThumb"

                            VerticalAlignment="Top"

                            Height="30"

                            Opacity="0" />

                        <StackPanel Name="ButtonStackPanel"

                            HorizontalAlignment="Right"

                            VerticalAlignment="Top"

                            Margin="0 5 6 0"

                            Orientation="Horizontal">

                            <Button Name="MinimizeButton"

                                Margin="0 0 2 0"

                                Width="21"

                                Height="21"

                                Style="{DynamicResource WindowButtonStyleKey}">

                                <Image

                                    Width="21"

                                    Height="21"

                                    Source="{StaticResource MinimizeNormalFocused}" />

                            </Button>

                            <Button Name="MaximizeButton"

                                Margin="0 0 2 0"

                                Height="21"

                                Width="21"

                                Style="{DynamicResource WindowButtonStyleKey}">

                                <Image

                                    Width="21"

                                    Height="21"

                                    Source="{StaticResource MaximizeNormalFocused}"/>

                            </Button>

                            <Button Name="CloseButton"

                                Width="21"

                                Height="21"

                                Style="{DynamicResource WindowButtonStyleKey}">

                                <Image

                                    Width="21"

                                    Height="21"

                                    Source="{StaticResource CloseNormalFocused}" />

                            </Button>

                        </StackPanel>

                        <Grid Name="HeaderContent"

                            Margin="6 0 78 0"

                            VerticalAlignment="Top"

                            Height="28"

                            IsHitTestVisible="False">

                            <Grid.ColumnDefinitions>

                                <ColumnDefinition Width="Auto" />

                                <ColumnDefinition              />

                            </Grid.ColumnDefinitions>

                            <Image Name="IconImage"

                                Margin="2 6 0 0"

                                Width="16"

                                Height="16"

                                Stretch="Fill"

                                RenderOptions.BitmapScalingMode="NearestNeighbor"

                                Visibility="{TemplateBinding ShowIcon, Converter={StaticResource BooleanToVisibilityConverterKey}}"

                                Source="{TemplateBinding Icon}" />

                            <TextBlock Name="Header" Grid.Column="1"

                                Margin="4 9 0 0"

                                Foreground="White"

                                TextTrimming="CharacterEllipsis"

                                TextWrapping="NoWrap"

                                Text="{TemplateBinding Title}" />

                        </Grid>

                        <Border Name="ContentHost"

                            Margin="5 29 5 5"

                            Background="{TemplateBinding Background}">

                            <ContentControl Content="{TemplateBinding Content}" />

                        </Border>

                        <Thumb Name="ResizeLeft"

                            Margin="0 6 0 6"

                            HorizontalAlignment="Left"

                            Width="6"

                            Cursor="SizeWE"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                        <Thumb Name="ResizeTop"

                            Margin="6 0 6 0"

                            VerticalAlignment="Top"

                            Height="4"

                            Cursor="SizeNS"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                        <Thumb Name="ResizeRight"

                            Margin="0 6 0 6"

                            HorizontalAlignment="Right"

                            Width="6"

                            Cursor="SizeWE"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                        <Thumb Name="ResizeBottom"

                            Margin="6 0 6 0"

                            VerticalAlignment="Bottom"

                            Height="6"

                            Cursor="SizeNS"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                        <Thumb Name="ResizeTopLeft"

                            HorizontalAlignment="Left"

                            VerticalAlignment="Top"

                            Width="6"

                            Height="6"

                            Cursor="SizeNWSE"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                        <Thumb Name="ResizeTopRight"

                            HorizontalAlignment="Right"

                            VerticalAlignment="Top"

                            Width="6"

                            Height="6"

                            Cursor="SizeNESW"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                        <Thumb Name="ResizeBottomRight"

                            HorizontalAlignment="Right"

                            VerticalAlignment="Bottom"

                            Width="6"

                            Height="6"

                            Cursor="SizeNWSE"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                        <Thumb Name="ResizeBottomLeft"

                            Width="6"

                            Height="6"

                            HorizontalAlignment="Left"

                            VerticalAlignment="Bottom"

                            Cursor="SizeNESW"

                            Opacity="0"

                            IsHitTestVisible="{TemplateBinding Resizable}" />

                    </Grid>

                    <ControlTemplate.Triggers>

                 <Trigger SourceName="CloseButton" Property="IsMouseOver" Value="True">

                            <Setter TargetName="CloseButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource CloseOver}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                        <Trigger SourceName="CloseButton" Property="IsPressed" Value="True">

                            <Setter TargetName="CloseButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource CloseDown}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition SourceName="MaximizeButton" Property="IsEnabled" Value="False" />

                                <Condition Property="Focused" Value="True" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MaximizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MaximizeDisabledFocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition SourceName="MaximizeButton" Property="IsEnabled" Value="False" />

                                <Condition Property="Focused" Value="False" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MaximizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MaximizeDisabledUnfocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <Trigger SourceName="MaximizeButton" Property="IsMouseOver" Value="True">

                            <Setter TargetName="MaximizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MaximizeOver}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                        <Trigger SourceName="MaximizeButton" Property="IsPressed" Value="True">

                            <Setter TargetName="MaximizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MaximizeDown}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition SourceName="MinimizeButton" Property="IsEnabled" Value="False" />

                                <Condition Property="Focused" Value="True" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MinimizeDisabledFocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition SourceName="MinimizeButton" Property="IsEnabled" Value="False" />

                                <Condition Property="Focused" Value="False" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MinimizeDisabledUnfocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <Trigger SourceName="MinimizeButton" Property="IsMouseOver" Value="True">

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MinimizeOver}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                        <Trigger SourceName="MinimizeButton" Property="IsPressed" Value="True">

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MinimizeDown}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition SourceName="MinimizeButton" Property="IsMouseOver" Value="True" />

                                <Condition Property="WindowState" Value="Minimized" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource RestoreOver}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition SourceName="MinimizeButton" Property="IsPressed" Value="True" />

                                <Condition Property="WindowState" Value="Minimized" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource RestoreDown}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="Focused" Value="True" />

                                <Condition SourceName="MinimizeButton" Property="IsPressed"   Value="False" />

                                <Condition SourceName="MinimizeButton" Property="IsMouseOver" Value="False" />

                                <Condition Property="WindowState" Value="Minimized" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource RestoreNormalFocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="Focused" Value="False" />

                                <Condition SourceName="MinimizeButton" Property="IsPressed"   Value="False" />

                                <Condition SourceName="MinimizeButton" Property="IsMouseOver" Value="False" />

                                <Condition Property="WindowState" Value="Minimized" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource RestoreNormalUnfocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <Trigger Property="Focused" Value="False">

                            <Setter

                                TargetName="TopLeftBackground"

                                Property="Source"

                                Value="{StaticResource TopLeftUnfocused}" />

                            <Setter

                                TargetName="TopMiddleBackground"

                                Property="Source"

                                Value="{StaticResource TopMiddleUnfocused}" />

                            <Setter

                                TargetName="TopRightBackground"

                                Property="Source"

                                Value="{StaticResource TopRightUnfocused}" />

                            <Setter

                                TargetName="LeftBackground"

                                Property="Source"

                                Value="{StaticResource LeftUnfocused}" />

                            <Setter

                                TargetName="RightBackground"

                                Property="Source"

                                Value="{StaticResource RightUnfocused}" />

                            <Setter

                                TargetName="BottomLeftBackground"

                                Property="Source"

                                Value="{StaticResource BottomLeftUnfocused}" />

                            <Setter

                                TargetName="BottomMiddleBackground"

                                Property="Source"

                                Value="{StaticResource BottomMiddleUnfocused}" />

                            <Setter

                                TargetName="BottomRightBackground"

                                Property="Source"

                                Value="{StaticResource BottomRightUnfocused}" />

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="Focused" Value="False" />

                                <Condition

                                    SourceName="CloseButton"

                                    Property="IsMouseOver"

                                    Value="False" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="CloseButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource CloseNormalUnfocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="Focused" Value="False" />

                                <Condition SourceName="MaximizeButton" Property="IsEnabled"   Value="True" />

                                <Condition SourceName="MaximizeButton" Property="IsMouseOver" Value="False" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MaximizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MaximizeNormalUnfocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="Focused" Value="False" />

                                <Condition SourceName="MinimizeButton" Property="IsEnabled"   Value="True" />

                                <Condition SourceName="MinimizeButton" Property="IsMouseOver" Value="False" />

                                <Condition Property="WindowState" Value="Normal" />

                            </MultiTrigger.Conditions>

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="21"

                                            Height="21"

                                            Source="{StaticResource MinimizeNormalUnfocused}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </MultiTrigger>

                        <Trigger SourceName="IconImage" Property="Source" Value="{x:Null}">

                            <Setter TargetName="IconImage" Property="Width" Value="0" />

                            <Setter TargetName="IconImage" Property="Margin" Value="0" />

                        </Trigger>

                        <Trigger Property="WindowState" Value="Minimized">

                            <Setter TargetName="LeftBackground"         Property="Visibility" Value="Hidden" />

                            <Setter TargetName="RightBackground"        Property="Visibility" Value="Hidden" />

                            <Setter TargetName="BottomLeftBackground"   Property="Visibility" Value="Hidden" />

                            <Setter TargetName="BottomMiddleBackground" Property="Visibility" Value="Hidden" />

                            <Setter TargetName="BottomRightBackground" Property="Visibility" Value="Hidden" />

                            <Setter Property="Resizable" Value="False" />

                        </Trigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="WindowState" Value="Minimized" />

                                <Condition Property="Focused" Value="True" />

                            </MultiTrigger.Conditions>

                            <Setter

                                TargetName="TopLeftBackground"

                                Property="Source"

                                Value="{StaticResource MinimizedTopLeftFocused}" />

                            <Setter

                                TargetName="TopMiddleBackground"

                                Property="Source"

                                Value="{StaticResource MinimizedTopMiddleFocused}" />

                            <Setter

                                TargetName="TopRightBackground"

                                Property="Source"

                                Value="{StaticResource MinimizedTopRightFocused}" />

                        </MultiTrigger>

                        <MultiTrigger>

                            <MultiTrigger.Conditions>

                                <Condition Property="WindowState" Value="Minimized" />

                                <Condition Property="Focused"     Value="False"     />

                            </MultiTrigger.Conditions>

                            <Setter

                                TargetName="TopLeftBackground"

                                Property="Source"

                                Value="{StaticResource MinimizedTopLeftUnfocused}" />

                            <Setter

                                TargetName="TopMiddleBackground"

                                Property="Source"

                                Value="{StaticResource MinimizedTopMiddleUnfocused}" />

                            <Setter

                                TargetName="TopRightBackground"

                                Property="Source"

                                Value="{StaticResource MinimizedTopRightUnfocused}" />

                        </MultiTrigger>

                        <Trigger Property="WindowState" Value="Maximized">

                            <Setter

                                TargetName="TopLeftBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="TopMiddleBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="TopRightBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="LeftBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="RightBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="BottomLeftBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="BottomMiddleBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="BottomRightBackground"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="Header"

                                Property="Visibility"

                                Value="Hidden" />

                            <Setter

                                TargetName="HeaderContent"

                                Property="Height"

                                Value="21" />

                            <Setter

                                TargetName="IconImage"

                                Property="Margin"

                                Value="2 0 0 0" />

                            <Setter

                                TargetName="ContentHost"

                                Property="Margin"

                                Value="0 0 0 0" />

                            <Setter

                                TargetName="ContentHost"

                                Property="BorderBrush"

                                Value="{StaticResource ContentHostBackgroundBrushKey}" />

                            <Setter

                                TargetName="ContentHost"

                                Property="BorderThickness"

                                Value="1" />

                            <Setter

                                TargetName="TopBackground"

                                Property="Background" Value="{StaticResource TopBackgroundBrushKey}" />

                            <Setter

                                TargetName="TopBackground"

                                Property="BorderBrush" Value="{StaticResource TopBackgroundBorderBrushKey}" />

                            <Setter

                                TargetName="TopBackground"

                                Property="BorderThickness" Value="0 0 0 1" />

                            <Setter

                                TargetName="DragThumb"

                                Property="IsHitTestVisible"

                                Value="False" />

                            <Setter

                                Property="Resizable"

                                Value="False" />

                            <Setter

                                TargetName="MinimizeButton"

                                Property="Margin"

                                Value="20 1 1 1" />

                            <Setter

                                TargetName="MaximizeButton"

                                Property="Margin"

                                Value="1" />

                            <Setter

                                TargetName="CloseButton"

                                Property="Margin"

                                Value="1" />

                            <Setter

                                TargetName="MinimizeButton"

                                Property="Width"

                                Value="18" />

                            <Setter

                                TargetName="MaximizeButton"

                                Property="Width"

                                Value="18" />

                            <Setter

                                TargetName="CloseButton"

                                Property="Width"

                                Value="18" />

                            <Setter

                                TargetName="MinimizeButton"

                                Property="Height"

                                Value="19" />

                            <Setter

                                TargetName="MaximizeButton"

                                Property="Height"

                                Value="19" />

                            <Setter

                                TargetName="CloseButton"

                                Property="Height"

                                Value="19" />

                            <Setter TargetName="MinimizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="18"

                                            Height="19"

                                            Source="{StaticResource MaximizedMinimizeImageKey}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                            <Setter TargetName="MaximizeButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="18"

                                            Height="19"

                                            Source="{StaticResource MaximizedRestoreImageKey}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                            <Setter TargetName="CloseButton" Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type Button}">

                                        <Image

                                            Width="18"

                                            Height="19"

                                            Source="{StaticResource MaximizedCloseImageKey}" />

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Trigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

</ResourceDictionary>

 

 

MDIChild.cs

 

 

using System;

using System.Collections.Generic;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Controls.Primitives;

using System.Windows.Input;

using System.Windows.Markup;

using System.Windows.Media;

using System.Windows.Threading;

 

namespace TestLibrary

{

    /// <summary>

    /// MDI 자식

    /// </summary>

    [ContentProperty("Content")]

    public class MDIChild : Control

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// ROUTED EVENT

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Public

 

        #region 종료 전 이벤트 - ClosingEvent

 

        /// <summary>

        /// 종료 전 이벤트

        /// </summary>

        public static readonly RoutedEvent ClosingEvent = EventManager.RegisterRoutedEvent

        (

            "Closing",

            RoutingStrategy.Bubble,

            typeof(ClosingEventArgs),

            typeof(MDIChild)

        );

 

        #endregion

        #region 종료 후 이벤트 - ClosedEvent

 

        /// <summary>

        /// 종료 후 이벤트

        /// </summary>

        public static readonly RoutedEvent ClosedEvent = EventManager.RegisterRoutedEvent

        (

            "Closed",

            RoutingStrategy.Bubble,

            typeof(RoutedEventArgs),

            typeof(MDIChild)

        );

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Dependency Property

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Public

 

        #region 위치 속성 - PositionProperty

 

        /// <summary>

        /// 위치 속성

        /// </summary>

        public static readonly DependencyProperty PositionProperty = DependencyProperty.Register

        (

            "Position",

            typeof(Point),

            typeof(MDIChild),

            new UIPropertyMetadata

            (

                new Point(-1, -1),

                new PropertyChangedCallback(PositionPropertyChangedCallback)

            )

        );

 

        #endregion

        #region 크기 조정 가능 여부 속성 - ResizableProperty

 

        /// <summary>

        /// 크기 조정 가능 여부 속성

        /// </summary>

        public static readonly DependencyProperty ResizableProperty = DependencyProperty.Register

        (

            "Resizable",

            typeof(bool),

            typeof(MDIChild),

            new UIPropertyMetadata(true)

        );

 

        #endregion

        #region 윈도우 상태 속성 - WindowStateProperty

 

        /// <summary>

        /// 윈도우 상태 속성

        /// </summary>

        public static readonly DependencyProperty WindowStateProperty = DependencyProperty.Register

        (

            "WindowState",

            typeof(WindowState),

            typeof(MDIChild),

            new UIPropertyMetadata

            (

                WindowState.Normal,

                new PropertyChangedCallback(WindowStatePropertyChangedCallback)

            )

        );

 

        #endregion

        #region 포커스 여부 - FocusedProperty

 

        /// <summary>

        /// 포커스 여부

        /// </summary>

        public static readonly DependencyProperty FocusedProperty = DependencyProperty.Register

        (

            "Focused",

            typeof(bool),

            typeof(MDIChild),

            new UIPropertyMetadata

            (

                false,

                new PropertyChangedCallback(FocusedPropertyChangedCallback)

            )

        );

 

        #endregion

        #region 아이콘 표시 여부 속성 - ShowIconProperty

 

        /// <summary>

        /// 아이콘 표시 여부 속성

        /// </summary>

        public static readonly DependencyProperty ShowIconProperty = DependencyProperty.Register

        (

            "ShowIcon",

            typeof(bool),

            typeof(MDIChild),

            new UIPropertyMetadata(true)

        );

 

        #endregion

        #region 아이콘 속성 - IconProperty

 

        /// <summary>

        /// 아이콘 속성

        /// </summary>

        public static readonly DependencyProperty IconProperty = DependencyProperty.Register

        (

            "Icon",

            typeof(ImageSource),

            typeof(MDIChild)

        );

 

        #endregion

        #region 제목 속성 - TitleProperty

 

        /// <summary>

        /// 제목 속성

        /// </summary>

        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register

        (

            "Title",

            typeof(string),

            typeof(MDIChild)

        );

 

        #endregion

        #region 최소화 상자 속성 - MinimizeBoxProperty

 

        /// <summary>

        /// 최소화 상자 속성

        /// </summary>

        public static readonly DependencyProperty MinimizeBoxProperty = DependencyProperty.Register

        (

            "MinimizeBox",

            typeof(bool),

            typeof(MDIChild),

            new UIPropertyMetadata

            (

                true,

                new PropertyChangedCallback(MinimizeBoxPropertyChangedCallback)

            )

        );

 

        #endregion

        #region 최대화 상자 속성 - MaximizeBoxProperty

 

        /// <summary>

        /// 최대화 상자 속성

        /// </summary>

        public static readonly DependencyProperty MaximizeBoxProperty = DependencyProperty.Register

        (

            "MaximizeBox",

            typeof(bool),

            typeof(MDIChild),

            new UIPropertyMetadata

            (

                true,

                new PropertyChangedCallback(MaximizeBoxPropertyChangedCallback)

            )

        );

 

        #endregion

        #region 닫기 상자 속성 - CloseBoxProperty

 

        /// <summary>

        /// 닫기 상자 속성

        /// </summary>

        public static readonly DependencyProperty CloseBoxProperty = DependencyProperty.Register

        (

            "CloseBox",

            typeof(bool),

            typeof(MDIChild),

            new UIPropertyMetadata

            (

                true,

                new PropertyChangedCallback(CloseBoxPropertyChangedCallback)

            )

        );

 

        #endregion

        #region 컨텐트 속성 - ContentProperty

 

        /// <summary>

        /// 컨텐트 속성

        /// </summary>

        public static readonly DependencyProperty ContentProperty = DependencyProperty.Register

        (

            "Content",

            typeof(UIElement),

            typeof(MDIChild)

        );

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Event

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 종료 전 이벤트 - Closing

 

        /// <summary>

        /// 종료 전 이벤트

        /// </summary>

        public event RoutedEventHandler Closing

        {

            add

            {

                AddHandler(ClosingEvent, value);

            }

            remove

            {

                RemoveHandler(ClosingEvent, value);

            }

        }

 

        #endregion

        #region 종료 후 이벤트 - Closed

 

        /// <summary>

        /// 종료 후 이벤트

        /// </summary>

        public event RoutedEventHandler Closed

        {

            add

            {

                AddHandler(ClosedEvent, value);

            }

            remove

            {

                RemoveHandler(ClosedEvent, value);

            }

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Internal

 

        #region Field

 

        /// <summary>

        /// 최소화시 너비

        /// </summary>

        internal const int MinimizedWidth = 160;

 

        /// <summary>

        /// 최소화시 높이

        /// </summary>

        internal const int MinimizedHeight = 29;

 

        #endregion

 

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Field

 

        /// <summary>

        /// 최소화 버튼

        /// </summary>

        private Button minimizeButton;

 

        /// <summary>

        /// 최대화 버튼

        /// </summary>

        private Button maximizeButton;

 

        /// <summary>

        /// 닫기 버튼

        /// </summary>

        private Button closeButton;

 

        /// <summary>

        /// 버튼 스택 패널

        /// </summary>

        private StackPanel buttonStackPanel;

 

        /// <summary>

        /// 원본 치수

        /// </summary>

        private Rect originalDimension;

 

        /// <summary>

        /// 최소화 위치

        /// </summary>

        private Point minimizedPosition = new Point(-1, -1);

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 위치 - Position

 

        /// <summary>

        /// 위치

        /// </summary>

        public Point Position

        {

            get

            {

                return (Point)GetValue(PositionProperty);

            }

            set

            {

                SetValue(PositionProperty, value);

            }

        }

 

        #endregion

        #region 크기 조정 가능 여부 - Resizable

 

        /// <summary>

        /// 크기 조정 가능 여부

        /// </summary>

        public bool Resizable

        {

            get

            {

                return (bool)GetValue(ResizableProperty);

            }

            set

            {

                SetValue(ResizableProperty, value);

            }

        }

 

        #endregion

        #region 윈도우 상태 - WindowState

 

        /// <summary>

        /// 윈도우 상태

        /// </summary>

        public WindowState WindowState

        {

            get

            {

                return (WindowState)GetValue(WindowStateProperty);

            }

            set

            {

                SetValue(WindowStateProperty, value);

            }

        }

 

        #endregion

        #region 포커스 여부 - Focused

 

        /// <summary>

        /// 포커스 여부

        /// </summary>

        public bool Focused

        {

            get

            {

                return (bool)GetValue(FocusedProperty);

            }

            set

            {

                SetValue(FocusedProperty, value);

            }

        }

 

        #endregion

        #region 아이콘 표시 여부 - ShowIcon

 

        /// <summary>

        /// 아이콘 표시 여부

        /// </summary>

        public bool ShowIcon

        {

            get

            {

                return (bool)GetValue(ShowIconProperty);

            }

            set

            {

                SetValue(ShowIconProperty, value);

            }

        }

 

        #endregion

        #region 아이콘 - Icon

 

        /// <summary>

        /// 아이콘

        /// </summary>

        public ImageSource Icon

        {

            get

            {

                return (ImageSource)GetValue(IconProperty);

            }

            set

            {

                SetValue(IconProperty, value);

            }

        }

 

        #endregion

        #region 제목 - Title

 

        /// <summary>

        /// 제목

        /// </summary>

        public string Title

        {

            get

            {

                return (string)GetValue(TitleProperty);

            }

            set

            {

                SetValue(TitleProperty, value);

            }

        }

 

        #endregion

        #region 최소화 상자 - MinimizeBox

 

        /// <summary>

        /// 최소화 상자

        /// </summary>

        public bool MinimizeBox

        {

            get

            {

                return (bool)GetValue(MinimizeBoxProperty);

            }

            set

            {

                SetValue(MinimizeBoxProperty, value);

            }

        }

 

        #endregion

        #region 최대화 상자 - MaximizeBox

 

        /// <summary>

        /// 최대화 상자

        /// </summary>

        public bool MaximizeBox

        {

            get

            {

                return (bool)GetValue(MaximizeBoxProperty);

            }

            set

            {

                SetValue(MaximizeBoxProperty, value);

            }

        }

 

        #endregion

        #region 닫기 상자 - CloseBox

 

        /// <summary>

        /// 닫기 상자

        /// </summary>

        public bool CloseBox

        {

            get

            {

                return (bool)GetValue(CloseBoxProperty);

            }

            set

            {

                SetValue(CloseBoxProperty, value);

            }

        }

 

        #endregion

        #region 컨텐트 - Content

 

        /// <summary>

        /// 컨텐트

        /// </summary>

        public UIElement Content

        {

            get

            {

                return (UIElement)GetValue(ContentProperty);

            }

            set

            {

                SetValue(ContentProperty, value);

            }

        }

 

        #endregion

 

        #region 컨테이너 - Container

 

        /// <summary>

        /// 컨테이너

        /// </summary>

        public MDIContainer Container { get; private set; }

 

        #endregion

        #region 버튼 패널 - ButtonPanel

 

        /// <summary>

        /// 버튼 패널

        /// </summary>

        public Panel ButtonPanel { get; private set; }

 

        #endregion

 

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 비 최대화 상태 - NonMaximizedState

 

        /// <summary>

        /// 비 최대화 상태

        /// </summary>

        private WindowState NonMaximizedState { get; set; }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Static

 

        #region 생성자 - MDIChild()

 

        /// <summary>

        /// 생성자

        /// </summary>

        static MDIChild()

        {

            DefaultStyleKeyProperty.OverrideMetadata

            (

                typeof(MDIChild),

                new FrameworkPropertyMetadata(typeof(MDIChild))

            );

        }

 

        #endregion

 

        ////////////////////////////////////////////////////////////////////////////////////////// Instance

        //////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MDIChild()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MDIChild()

        {

            Focusable = IsTabStop = false;

 

            Loaded   += Control_Loaded;

            GotFocus += Control_GotFocus;

            KeyDown  += Control_KeyDown;

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

 

        #region 위치 속성 변경시 콜백 처리하기 - PositionPropertyChangedCallback(d, e)

 

        /// <summary>

        /// 위치 속성 변경시 콜백 처리하기

        /// </summary>

        /// <param name="d">의존 객체</param>

        /// <param name="e">이벤트 인자</param>

        private static void PositionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)

        {

            if((Point)e.NewValue == (Point)e.OldValue)

            {

                return;

            }

 

            MDIChild mdiChild = d as MDIChild;

 

            Point newPosition = (Point)e.NewValue;

 

            Canvas.SetTop (mdiChild, newPosition.Y < 0 ? 0 : newPosition.Y);

            Canvas.SetLeft(mdiChild, newPosition.X < 0 ? 0 : newPosition.X);

        }

 

        #endregion

        #region 윈도우 상태 속성 변경시 콜백 처리하기 - WindowStatePropertyChangedCallback(d, e)

 

        /// <summary>

        /// 윈도우 상태 속성 변경시 콜백 처리하기

        /// </summary>

        /// <param name="d">의존 객체</param>

        /// <param name="e">이벤트 인자</param>

        private static void WindowStatePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)

        {

            MDIChild     mdiChild     = d as MDIChild;

            MDIContainer mdiContainer = mdiChild.Container;

 

            WindowState previousWindowState = (WindowState)e.OldValue;

            WindowState windowState         = (WindowState)e.NewValue;

 

            if(mdiChild.Container == null || previousWindowState == windowState)

            {

                return;

            }

 

            if(previousWindowState == WindowState.Maximized)

            {

                if(mdiContainer.ActiveMDIChild.WindowState != WindowState.Maximized)

                {

                    for(int i = 0; i < mdiContainer.Children.Count; i++)

                    {

                        if

                        (

                            mdiContainer.Children[i] != mdiChild &&

                            mdiContainer.Children[i].WindowState == WindowState.Maximized &&

                            mdiContainer.Children[i].MaximizeBox

                        )

                        {

                            mdiContainer.Children[i].WindowState = WindowState.Normal;

                        }

                    }

 

                    ScrollViewer scrollViewer = (ScrollViewer)((Grid)mdiContainer.Content).Children[1];

 

                    scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

                    scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;

                }

 

                mdiChild.ButtonPanel.Children.Clear();

 

                mdiChild.ButtonPanel = null;

 

                mdiChild.buttonStackPanel.Children.Add(mdiChild.minimizeButton);

                mdiChild.buttonStackPanel.Children.Add(mdiChild.maximizeButton);

                mdiChild.buttonStackPanel.Children.Add(mdiChild.closeButton   );

            }

 

            if(previousWindowState == WindowState.Minimized)

            {

                mdiChild.minimizedPosition = mdiChild.Position;

            }

 

            switch(windowState)

            {

                case WindowState.Normal :

                {

                    mdiChild.Position = new Point(mdiChild.originalDimension.X, mdiChild.originalDimension.Y);

                    mdiChild.Width    = mdiChild.originalDimension.Width;

                    mdiChild.Height   = mdiChild.originalDimension.Height;

 

                    break;

                }

                case WindowState.Minimized :

                {

                    if(previousWindowState == WindowState.Normal)

                    {

                        mdiChild.originalDimension = new Rect

                        (

                            mdiChild.Position.X,

                            mdiChild.Position.Y,

                            mdiChild.ActualWidth,

                            mdiChild.ActualHeight

                        );

                    }

 

                    double newLeft;

                    double newTop;

 

                    if(mdiChild.minimizedPosition.X >= 0 || mdiChild.minimizedPosition.Y >= 0)

                    {

                        newLeft = mdiChild.minimizedPosition.X;

                        newTop  = mdiChild.minimizedPosition.Y;

                    }

                    else

                    {

                        List<Rect> minimizedWindowList = new List<Rect>();

 

                        for(int i = 0; i < mdiContainer.Children.Count; i++)

                        {

                            MDIChild child = mdiContainer.Children[i];

 

                            if(child != mdiChild && child.WindowState == WindowState.Minimized)