public class CustomWnd : System.Windows.Window
{
static CustomWnd()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomWnd), new FrameworkPropertyMetadata(typeof(CustomWnd)));
} public CustomWnd()
{
CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, CloseWindow));
CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, MaximizeWindow, CanResizeWindow));
CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, MinimizeWindow));
CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, RestoreWindow, CanResizeWindow));
} private void CanResizeWindow(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = ResizeMode == ResizeMode.CanResize || ResizeMode == ResizeMode.CanResizeWithGrip;
} private void RestoreWindow(object sender, ExecutedRoutedEventArgs e)
{
this.WindowState = System.Windows.WindowState.Normal;
} private void MinimizeWindow(object sender, ExecutedRoutedEventArgs e)
{
this.WindowState = System.Windows.WindowState.Minimized;
} private void MaximizeWindow(object sender, ExecutedRoutedEventArgs e)
{
this.WindowState = System.Windows.WindowState.Maximized;
} private void CloseWindow(object sender, ExecutedRoutedEventArgs e)
{
this.Close();
}
}
<Style TargetType="{x:Type wnd:CustomWnd}" BasedOn="{StaticResource ResourceKey={x:Type Window}}">
<Setter Property="WindowStyle" Value="SingleBorderWindow"/>
<Setter Property="AllowsTransparency" Value="False"/>
<Setter Property="BorderBrush" Value="Green"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="UseLayoutRounding" Value="True"/>
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CornerRadius="0" GlassFrameThickness="1" UseAeroCaptionButtons="False" NonClientFrameEdges="None" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type wnd:CustomWnd}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="LayoutRoot" Background="{TemplateBinding Background}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions> <Grid x:Name="PART_WindowTitleGrid" Grid.Row="0" Height="30" Background="{TemplateBinding BorderBrush}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0">
<Image Source="{TemplateBinding Icon}" Margin="0,0,5,0"/>
<TextBlock Text="{TemplateBinding Title}" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center"/>
</StackPanel> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5,0">
<Button Width="24" Height="24" IsTabStop="False" WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource SysBtnStyle}" Command="{x:Static SystemCommands.MinimizeWindowCommand}">
<Button.Content>
<Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,0 L10,0" Margin="0,5,0,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button.Content>
</Button>
<Button x:Name="PART_MAX" Width="24" Height="24" IsTabStop="False" WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource SysBtnStyle}"/>
<Button Width="24" Height="24" IsTabStop="False" WindowChrome.IsHitTestVisibleInChrome="True" Style="{StaticResource SysCloseBtnStyle}" Command="{x:Static SystemCommands.CloseWindowCommand}">
<Button.Content>
<Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,0 L7.07,7.07 M0,7.07 L7.07,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button.Content>
</Button>
</StackPanel>
</Grid> <AdornerDecorator Grid.Row="1" KeyboardNavigation.IsTabStop="False">
<ContentPresenter x:Name="MainContentPresenter" KeyboardNavigation.TabNavigation="Cycle" />
</AdornerDecorator> <ResizeGrip x:Name="ResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="1"
IsTabStop="False" Visibility="Hidden" WindowChrome.ResizeGripDirection="BottomRight" />
</Grid>
</Border> <ControlTemplate.Triggers>
<Trigger Property="WindowState" Value="Maximized">
<Setter TargetName="PART_MAX" Property="Command" Value="{x:Static SystemCommands.RestoreWindowCommand}"/>
<Setter TargetName="PART_MAX" Property="Content">
<Setter.Value>
<Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,3 L5,3 L5,8 L0,8Z M3,3 L3,0 L8,0 L8,5 L5,5" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Setter.Value>
</Setter>
</Trigger> <Trigger Property="WindowState" Value="Normal">
<Setter TargetName="PART_MAX" Property="Command" Value="{x:Static SystemCommands.MaximizeWindowCommand}"/>
<Setter TargetName="PART_MAX" Property="Content">
<Setter.Value>
<Path Stroke="White" StrokeThickness="2" Fill="Transparent" Data="M0,0 L7.07,0 L7.07,7.07 L0,7.07Z" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Setter.Value>
</Setter>
</Trigger> <Trigger Property="IsActive" Value="False">
<Setter Property="BorderBrush" Value="#FF6F7785" />
</Trigger> <Trigger Property="ResizeMode" Value="NoResize">
<Setter TargetName="PART_MAX" Property="Visibility" Value="Collapsed" />
</Trigger> <MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ResizeMode" Value="CanResizeWithGrip" />
<Condition Property="WindowState" Value="Normal" />
</MultiTrigger.Conditions> <Setter TargetName="ResizeGrip" Property="Visibility" Value="Visible" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

 

Custom Window的更多相关文章

  1. jquery easy ui 学习 (2) customtools window

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. Caliburn.Micro 杰的入门教程5,Window Manager 窗口管理器

    Caliburn.Micro 杰的入门教程1(翻译)Caliburn.Micro 杰的入门教程2 ,了解Data Binding 和 Events(翻译)Caliburn.Micro 杰的入门教程3, ...

  3. windows消息机制详解(转载)

    消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...

  4. sublime text3 快捷键设置

    //插入到key binding user 里面,浏览器安装路径修改成自己的路径 1[ //firefox测试快捷键 { "keys":["f3"], &quo ...

  5. 准备.Net转前端开发-WPF界面框架那些事,搭建基础框架

    题外话 最近都没怎么写博客,主要是最近在看WPF方面的书<wpf-4-unleashed.pdf>,挑了比较重要的几个章节学习了下WPF基础技术.另外,也把这本书推荐给目前正在从事WPF开 ...

  6. Flink DataStream API Programming Guide

    Example Program The following program is a complete, working example of streaming window word count ...

  7. 【Qt】Qt之自定义界面(添加自定义标题栏)【转】

    简述 通过上节内容,我们实现了自定义窗体的移动,但是我们缺少一个标题栏来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭的按钮. 自定义标题栏后,所有的控件我们都可以定制,比如:在标题栏中添加换 ...

  8. Qt之自定义界面(添加自定义标题栏)

    简述 通过上节内容,我们实现了自定义窗体的移动,但是我们缺少一个标题栏来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭的按钮. 自定义标题栏后,所有的控件我们都可以定制,比如:在标题栏中添加换 ...

  9. Silverlight之OOB模式下的一些事

    本文简介: 1.为什么要使用OOB?使用OOB的作用? 2.如何实现OOB模式 3.对OOB进行一些设置: 4.检测OOB的安装状态: 5.更新应用程序: 6.WebBrowser控件: 7.桌面通知 ...

随机推荐

  1. JAVA 数组作为方法参数—传递地址

    package Code411;//数组作为方法参数—传递地址public class DodeArrayParam { public static void main(String[] args) ...

  2. sqlalchemy的使用

    from sqlalchemy import Column, Integer, String, Text, ForeignKey, DateTime, UniqueConstraint, Index ...

  3. 切换Allegro PCB Editor

    操作系统:Windows 10 x64 工具1:Allegro PCB Editor 菜单File > Change Editor... 在Product Choices对话框中,就可以选择想要 ...

  4. jquery 第一章

    1.本章目标    了解jquery    了解jquery和js的区别    掌握jquery的入门    掌握jquery对象和dom对象的区别2.jquery简介    jquery是一个轻量级 ...

  5. vue项目关闭eslint检查

    前言 vue项目在用旧版本的vue-cli创建的时候,会询问是否添加eslint的检查, 后来的版本在创建的时候是直接添加了eslint检查. 有时候我们开发习惯不是那么严格的时候, 会不在意这些缩进 ...

  6. 详解 CAP 定理 Consistency(一致性)、 Availability(可用性)、Partition tolerance(分区容错性)

    CAP原则又称CAP定理,指的是在一个分布式系统中,Consistency(一致性). Availability(可用性).Partition tolerance(分区容错性),三者不可得兼. 分布式 ...

  7. python安装多版本

    39.107.96.81 root 123123 pyenv#可以实现python多版本控制与切换 pyenv local 3.5.1 ipython#更方便的编写python,可以补全命令彩色显示等 ...

  8. php实现微信企业向用户付款

    <?php header('content-type:text/html;charset=utf-8'); $data['mch_appid']='##################';//商 ...

  9. iOS12系统应用发送普通邮实现发送

    iOS12系统应用发送普通邮实现发送 构建好邮件以后,可以发送该邮件.此时需要使用mailComposeDelegate属性,该属性用来设置委托,其语法形式如下: unowned(unsafe) va ...

  10. 二分三元组 CodeForces - 251A

    题目链接: https://vjudge.net/problem/35188/origin 题目大意: 要求你找到一个 i < j < k时有 a[k]-a[i] <= d的组的个数 ...