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.桌面通知 ...
随机推荐
- Haystack-全文搜索框架
Haystack 1.什么是Haystack Haystack是django的开源全文搜索框架(全文检索不同于特定字段的模糊查询,使用全文检索的效率更高 ),该框架支持Solr,Elasticsear ...
- 【自然语言处理】LDA
飞机票 飞机票 步骤: 1. 离线求的模型 2. 用模型对新文本预测topic,取topic概率带到阈值(例如0.2)且topN个topic,例如doc1 :topic1:0.5, topic2:0. ...
- .net core2.x - Identity - 简介
- 关闭 Visual Studio 的 Browser Link 功能
最近公司弄新项目需要用 MVC,就把 IDE 升级到了 Visual Studio 2013,在开发的时候发现有好多请求一个本地49925的端口 . 很奇怪,一开始以为是 Visual Studio ...
- Zookeeper集群搭建步骤及相关知识点深入了解
1.zookeeper概念 zookeeper是一个分布式协调服务:a:zookeeper是为别的分布式程序服务的 b:zookeeper本身就是一个分布式程序(只要半数以上节点存活,zookeepe ...
- 整理一下python中with的用法
ith替代了之前在python里使用try...finally来做清理工作的方法.基本形式如下: with expression [as variable]: with-block 当expressi ...
- c++中字符串的反转
1.对于用char定义的字符串:使用string.h中的strrev函数 #include <iostream> #include <cstring> using namesp ...
- Mapreduce的排序(全局排序、分区加排序、Combiner优化)
一.MR排序的分类 1.部分排序:MR会根据自己输出记录的KV对数据进行排序,保证输出到每一个文件内存都是经过排序的: 2.全局排序: 3.辅助排序:再第一次排序后经过分区再排序一次: 4.二次排序: ...
- JVM内存简单总结
根据自己的认识,简单总结下Java中的数据存储及内存分析. Java中的内存大致可以分为三块:栈内存.堆内存.方法区内存,看图说话. 1).栈 栈(stack):栈是限定仅在表头进行插入和删除操作的线 ...
- vscode断点调试工程化服务端文件
一.创建express应用我们使用express-generator创建一个新的express应用.1.全局安装express-generator // 安装 sudo npm install exp ...