Custom Window
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的更多相关文章
- jquery easy ui 学习 (2) customtools window
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Caliburn.Micro 杰的入门教程5,Window Manager 窗口管理器
Caliburn.Micro 杰的入门教程1(翻译)Caliburn.Micro 杰的入门教程2 ,了解Data Binding 和 Events(翻译)Caliburn.Micro 杰的入门教程3, ...
- windows消息机制详解(转载)
消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...
- sublime text3 快捷键设置
//插入到key binding user 里面,浏览器安装路径修改成自己的路径 1[ //firefox测试快捷键 { "keys":["f3"], &quo ...
- 准备.Net转前端开发-WPF界面框架那些事,搭建基础框架
题外话 最近都没怎么写博客,主要是最近在看WPF方面的书<wpf-4-unleashed.pdf>,挑了比较重要的几个章节学习了下WPF基础技术.另外,也把这本书推荐给目前正在从事WPF开 ...
- Flink DataStream API Programming Guide
Example Program The following program is a complete, working example of streaming window word count ...
- 【Qt】Qt之自定义界面(添加自定义标题栏)【转】
简述 通过上节内容,我们实现了自定义窗体的移动,但是我们缺少一个标题栏来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭的按钮. 自定义标题栏后,所有的控件我们都可以定制,比如:在标题栏中添加换 ...
- Qt之自定义界面(添加自定义标题栏)
简述 通过上节内容,我们实现了自定义窗体的移动,但是我们缺少一个标题栏来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭的按钮. 自定义标题栏后,所有的控件我们都可以定制,比如:在标题栏中添加换 ...
- Silverlight之OOB模式下的一些事
本文简介: 1.为什么要使用OOB?使用OOB的作用? 2.如何实现OOB模式 3.对OOB进行一些设置: 4.检测OOB的安装状态: 5.更新应用程序: 6.WebBrowser控件: 7.桌面通知 ...
随机推荐
- C# 微信开发-----微信会员卡(二)
主要说说如何使用微信的激活会员卡 如图: 点击激活会员卡时,要跳转到如下的图片: 要实现这个功能,首先我们在创建会员卡后就操作如下代码 #region 添加激活时的自定义字段 string custo ...
- Java面试题复习笔记(Web方向)
1.Http中get和post请求的区别? 共同点:都是Http请求方式,用户可以通过不同的请求方式完成对资源(Url)的操作.具体来讲就是get一般用于获取/查询资源信息,post用于更新资源信息. ...
- python第六篇文件处理类型
阅读目录 一 文件操作 二 打开文件的模式 三 操作文件的方法 四 文件内光标移动 五 文件的修改 文件处理 ...
- PHP 必知的 16 个编程法则
以双下划线(__)开头的方法称为魔术方法 -__construct():类的构造方法: -__destruct():类的析构方法: -__call($funName, $arguments):当访问未 ...
- 论文阅读笔记四十:Deformable ConvNets v2: More Deformable, Better Results(CVPR2018)
论文源址:https://arxiv.org/abs/1811.11168 摘要 可变形卷积的一个亮点是对于不同几何变化的物体具有适应性.但也存在一些问题,虽然相比传统的卷积网络,其神经网络的空间形状 ...
- 末学者笔记--Linux中RAID磁盘阵列及centos7启动过程
<一>RAID概念 磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有冗余能力的阵列”之意. 磁盘阵列是由很多价格较便 ...
- 01.pandas
01.Series # -*- coding: utf-8 -*- """ Series 객체 특징 - pandas 제공 1차원 자료구성 - DataFrame 칼 ...
- Spark SQL大数据处理并写入Elasticsearch
SparkSQL(Spark用于处理结构化数据的模块) 通过SparkSQL导入的数据可以来自MySQL数据库.Json数据.Csv数据等,通过load这些数据可以对其做一系列计算 下面通过程序代码来 ...
- datatables隐藏列与createdRow渲染bootstrapSwitch形成的BUG
背景: 昨天写了一个页面用于规则库的增删改查. 数据使用datatables渲染,后端返回数据由前端进行一次性渲染和分页. 隐藏列: 排序的ID不展示,但是排序又想按照ID来排,所以把ID单独作为一列 ...
- KaliLinux常用服务配置教程DHCP服务工作流程
KaliLinux常用服务配置教程DHCP服务工作流程 DHCP服务工作流程如图1.1所示. 具体的工作流程如下所示: (1)DHCP客户端以广播的方式发出DHCP Discover报文. (2)所有 ...