728x90
반응형
728x170
▶ CustomWindow.xaml
<Window x:Class="TestProject.CustomWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="640"
Height="520"
WindowStyle="None"
ResizeMode="NoResize"
AllowsTransparency="True"
Background="Transparent"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<BitmapImage x:Key="CloseBitmapImageKey"
UriSource="/IMAGE/close.png" />
<BitmapImage x:Key="CloseOverBitmapImageKey"
UriSource="/IMAGE/close_over.png" />
<Style x:Key="CloseImageStyleKey" TargetType="Image">
<Setter Property="Source" Value="{StaticResource CloseBitmapImageKey}" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" Value="{StaticResource CloseOverBitmapImageKey}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="SkyButtonStyleKey" TargetType="Button">
<Setter Property="Background" Value="#1593fd" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter Name="contentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#1179d1" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="WhiteButtonStyleKey" TargetType="Button">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="#505050" />
<Setter Property="BorderBrush" Value="#a5a5a5" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="{TemplateBinding Background}">
<Border
Width="{Binding RelativeSource={RelativeSource AncestorType=Button, Mode=FindAncestor}, Path=ActualWidth}"
Height="{Binding RelativeSource={RelativeSource AncestorType=Button, Mode=FindAncestor}, Path=ActualHeight}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter Name="contentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#dde7f1" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid
Margin="20"
Background="#1593fd">
<Grid.Effect>
<DropShadowEffect
BlurRadius="15"
Color="LightGray"
Direction="-90"
RenderingBias="Quality"
ShadowDepth="2" />
</Grid.Effect>
<Grid.RowDefinitions>
<RowDefinition Height="25px" />
<RowDefinition Height="*" />
<RowDefinition Height="1px" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- 제목 그리드 -->
<Grid Name="titleGrid" Grid.Row="0"
Background="#1593fd">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="31px" />
</Grid.ColumnDefinitions>
<Image Name="iconImage" Grid.Column="0"
Margin="10 0 0 0"
Width="16px"
Height="16px"
Source="/IMAGE/logo.png" />
<TextBlock Name="titleTextBlock" Grid.Column="1"
VerticalAlignment="Center"
Margin="5 0 0 0"
Foreground="White"
FontSize="12px"
Text="테스트" />
<Image Name="closeImage" Grid.Column="2"
Style="{StaticResource CloseImageStyleKey}"
Width="15px"
Height="15px" />
</Grid>
<!-- 컨텐트 그리드 -->
<Grid Name="contentGrid" Grid.Row="1"
Background="White" />
<!-- 구분선 그리드 -->
<Grid Grid.Row="2"
Background="#dddddd" />
<!-- 컨트롤 그리드 -->
<Grid Grid.Row="3"
Background="#f5f5f5">
<Grid.RowDefinitions>
<RowDefinition Height="20px" />
<RowDefinition Height="30px" />
<RowDefinition Height="20px" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20px" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100px" />
<ColumnDefinition Width="10px" />
<ColumnDefinition Width="100px" />
<ColumnDefinition Width="20px" />
</Grid.ColumnDefinitions>
<Button Name="okButton" Grid.Row="1" Grid.Column="2"
Style="{StaticResource SkyButtonStyleKey}"
Width="100"
Height="30"
Content="확인" />
<Button Name="cancelButton" Grid.Row="1" Grid.Column="4"
Style="{StaticResource WhiteButtonStyleKey}"
Width="100"
Height="30"
Content="취소" />
</Grid>
</Grid>
</Window>
728x90
▶ CustomWindow.xaml.cs
using System.Windows;
using System.Windows.Input;
namespace TestProject
{
/// <summary>
/// 커스텀 윈도우
/// </summary>
public partial class CustomWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - CustomWindow()
/// <summary>
/// 생성자
/// </summary>
public CustomWindow()
{
InitializeComponent();
PreviewMouseLeftButtonDown += Window_PreviewMouseLeftButtonDown;
this.closeImage.MouseLeftButtonUp += closeImage_MouseLeftButtonUp;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 PREVIEW 마우스 왼쪽 버튼 UP 처리하기 - Window_PreviewMouseLeftButtonDown(sender, e)
/// <summary>
/// 윈도우 PREVIEW 마우스 왼쪽 버튼 UP 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if(e.OriginalSource == this.closeImage)
{
return;
}
if(e.Source == this.okButton || e.Source == this.cancelButton)
{
return;
}
DragMove();
}
#endregion
#region 닫기 이미지 마우스 왼쪽 버튼 UP 처리하기 - closeImage_MouseLeftButtonUp(sender, e)
/// <summary>
/// 닫기 이미지 마우스 왼쪽 버튼 UP 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void closeImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Close();
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] ImageAwesome 엘리먼트 : Spin/SpinDuration 속성을 사용해 아이콘 회전시키기 (0) | 2021.09.11 |
---|---|
[C#/WPF] 누겟 설치 : FontAwesome.WPF (0) | 2021.09.11 |
[C#/WPF] GOM 플레이어 모방하기 (0) | 2021.09.05 |
[C#/WPF] LinearGradientBrush 엘리먼트 사용하기 (0) | 2021.08.24 |
[C#/WPF] Vector 구조체 : 각도에서 벡터 구하기 (0) | 2021.08.20 |
[C#/WPF] Application 클래스 : Restart 메소드를 사용해 애플리케이션 재시작하기 (0) | 2021.08.19 |
[C#/WPF] Vector 구조체 : 벡터 각도 구하기 (0) | 2021.08.19 |
[C#/WPF] ResourceDictionary 클래스 : MergedDictionaries 속성을 사용해 Application 객체의 리소스 사용하기 (0) | 2021.07.08 |
[C#/WPF] ControlTemplate 엘리먼트 : Thumb/ScrollBar/ListBoxItem 엘리먼트 정의하기 (0) | 2021.06.07 |
[C#/WPF] HwndSource 클래스 : FromHwnd 정적 메소드를 사용해 윈도우 핸들로 윈도우 구하기 (0) | 2021.06.07 |
댓글을 달아 주세요