WPF 自定义标题栏
在做客户端应用程序时,往往觉得Windows自带的标题栏没有样式,不太好看,下面分享自自定义的一个Windows工具
效果图:
<Style x:Key="Buttonclock" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Width="">
<Border BorderThickness=""/>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Opacity="0.7"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" TargetName="contentPresenter" Value=""/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Opacity" TargetName="contentPresenter" Value="0.7"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Opacity" TargetName="contentPresenter" Value=""/>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="Buttonmini_minwindow" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ControlTemplate.Resources>
<Storyboard x:Key="Sbmini1">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="rectangle">
<DiscreteObjectKeyFrame KeyTime="" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value=""/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="contentPresenter">
<EasingDoubleKeyFrame KeyTime="" Value="0.6"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value=""/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="Sbmini2">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="rectangle">
<DiscreteObjectKeyFrame KeyTime="0:0:0.2" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
<SplineDoubleKeyFrame KeyTime="" Value=""/>
<SplineDoubleKeyFrame KeyTime="0:0:0.2" Value=""/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="contentPresenter">
<SplineDoubleKeyFrame KeyTime="" Value=""/>
<SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0.6"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<Rectangle x:Name="rectangle" RadiusX="" Stroke="{x:Null}" Height="" Width="" Visibility="Hidden">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#003099E2" Offset=""/>
<GradientStop Color="#67FDFDFD" Offset="0.072"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Opacity="0.6"/>
<Border BorderBrush="Black" BorderThickness="" Opacity="">
<Border.Background>
<RadialGradientBrush>
<GradientStop Color="#00000000" Offset=""/>
<GradientStop Color="White" Offset=""/>
</RadialGradientBrush>
</Border.Background>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.ExitActions>
<BeginStoryboard x:Name="Sbmini2_BeginStoryboard" Storyboard="{StaticResource Sbmini2}"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Sbmini1}"/>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsMouseOver" Value="False"/>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Margin" TargetName="contentPresenter" Value=""/>
<Setter Property="Visibility" TargetName="rectangle" Value="Visible"/>
<Setter Property="Fill" TargetName="rectangle">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#003099E2" Offset=""/>
<GradientStop Color="#671F1F1F" Offset="0.072"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="Buttonclose_mainwidow" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ControlTemplate.Resources>
<Storyboard x:Key="sbstory1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value=""/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="" Value="0.6"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value=""/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="sbstory2">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.6"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
<EasingDoubleKeyFrame KeyTime="" Value=""/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value=""/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<Rectangle x:Name="rectangle" Margin="-12.167,0,0,-9.167" RadiusY="5.5" RadiusX="" Stroke="#FF379FE6" StrokeThickness="" Width="Auto" Clip="M12.167,0 L54.167,0 L54.167,20 L12.167,20 z" Opacity="">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#99D91A1D" Offset="0.396"/>
<GradientStop Color="#00D91A1D" Offset="0.726"/>
<GradientStop Color="#7FFE5B5E"/>
<GradientStop Color="#BFD6070B" Offset="0.104"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Image Source="/PermissionsDemo;component/image/csmmainwidow_Images/icons92.png" Stretch="None" Height="" Width="" Margin="0,0,0,-3" Opacity="" Visibility="Hidden"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="" />
<Image x:Name="image" Margin="0,0,0,-3" Source="/PermissionsDemo;component/image/csmmainwidow_Images/icons85.png" Stretch="None" Width="" Height="" Visibility="Visible" Opacity="0.6"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.ExitActions>
<BeginStoryboard x:Name="sbstory2_BeginStoryboard" Storyboard="{StaticResource sbstory2}"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource sbstory1}"/>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsMouseOver" Value="False"/>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Opacity" TargetName="rectangle" Value="0.8"/>
<Setter Property="Margin" TargetName="image" Value="1,0,0,-4"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Grid x:Name="LayoutRoot" Width="" Height="">
<DockPanel LastChildFill="False" HorizontalAlignment="Right" Height="">
<Button Style="{StaticResource Buttonclock}">
<Image Source="/PermissionsDemo;component/image/csmmainwidow_Images/icons96.png" Stretch="Fill" Width="" Height="" RenderOptions.BitmapScalingMode="NearestNeighbor" />
</Button>
<Button Style="{StaticResource Buttonclock}" Margin="12,0,0,0">
<Image Source="/PermissionsDemo;component/image/csmmainwidow_Images/icons95.png" Stretch="Fill" Width="" Height="" RenderOptions.BitmapScalingMode="NearestNeighbor" />
</Button>
<Button Style="{StaticResource Buttonclock}" Margin="12,0">
<Image Height="" Source="/PermissionsDemo;component/image/csmmainwidow_Images/question.png" Stretch="Fill" Width="" RenderOptions.BitmapScalingMode="NearestNeighbor" />
</Button>
<Border BorderBrush="#66FFFFFF" BorderThickness="1,0" Width="">
<Border.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#99000000" Offset="0.323"/>
<GradientStop Offset=""/>
</LinearGradientBrush>
</Border.OpacityMask>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF25679B" Offset=""/>
<GradientStop Color="#002B72A9" Offset=""/>
<GradientStop Color="#FF2975AF" Offset="0.6"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Button Margin="" Style="{StaticResource Buttonmini_minwindow}" Width="" VerticalAlignment="Center">
<Rectangle Fill="#FFF4F4F5" Height="" VerticalAlignment="Bottom" Stroke="#C021698F" Width="" Margin="0,10,0,0"/>
</Button>
<Border BorderBrush="#66FFFFFF" BorderThickness="1,0" Width="">
<Border.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#99000000" Offset="0.323"/>
<GradientStop Offset=""/>
</LinearGradientBrush>
</Border.OpacityMask>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF25679B" Offset=""/>
<GradientStop Color="#002B72A9" Offset=""/>
<GradientStop Color="#FF2975AF" Offset="0.6"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Button Margin="" Style="{StaticResource Buttonmini_minwindow}" Width="" VerticalAlignment="Center">
<Path Data="M2.5,2.5 L2.5,6.5 7.5,6.5 7.5,2.5 z M0.5,0.5 L9.5,0.5 9.5,8.5 0.5,8.5 z" HorizontalAlignment="Center" Height="" Stretch="Fill" VerticalAlignment="Center" Width="" Stroke="#C021698F" Margin="0,4,0,0">
<Path.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE7E7E7" Offset=""/>
<GradientStop Color="WhiteSmoke"/>
</LinearGradientBrush>
</Path.Fill>
</Path>
</Button>
<Border BorderBrush="#66FFFFFF" BorderThickness="1,0" Width="">
<Border.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#99000000" Offset="0.323"/>
<GradientStop Offset=""/>
</LinearGradientBrush>
</Border.OpacityMask>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF25679B" Offset=""/>
<GradientStop Color="#002B72A9" Offset=""/>
<GradientStop Color="#FF2975AF" Offset="0.6"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Button RenderOptions.BitmapScalingMode="NearestNeighbor" Content="Button" HorizontalAlignment="Center" Margin="0,-1,0,0" Style="{StaticResource Buttonclose_mainwidow}" Width=""/>
</DockPanel>
</Grid>
由于自己初学WPF,代码中可能有点冗余。
下面是工具栏中图片资源: mainwidow_Images.7z
页面资源文件源码:Titel.7z
WPF 自定义标题栏的更多相关文章
- WPF 自定义标题栏 自定义菜单栏
自定义标题栏 自定义列表,可以直接修改WPF中的ListBox模板,也用这样类似的效果.但是ListBox是不能设置默认选中状态的. 而我们需要一些复杂的UI效果,还是直接自定义控件来的快 GitHu ...
- WPF中自定义标题栏时窗体最大化处理之WindowChrome
注意: 本文方法基础是WindowChrome,而WindowChrome在.NET Framework 4.5之后才集成发布的.见:WindowChrome Class 在.NET Framewor ...
- WPF 自定义柱状图 BarChart
WPF 自定义柱状图 当前的Telerik控件.DevExpress控件在图表控件方面做得不错,但是有时项目中需要特定的样式,不是只通过修改图表的模板和样式就能实现的. 或者说,通过修改当前的第三方控 ...
- WPF 自定义 MessageBox (相对完善版)
WPF 自定义 MessageBox (相对完善版) 基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当 ...
- WPF 自定义 MessageBox (相对完善版 v1.0.0.6)
基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当你不得不弹出一个消息框通知用户消息时(虽然很不建议在程序中频繁 ...
- wpf 自定义窗口,最大化时覆盖任务栏解决方案
原文:wpf 自定义窗口,最大化时覆盖任务栏解决方案 相信很多人使用wpf时会选择自定义美观的窗口,因此会设置WindowStyle="None" 取消自带的标题栏.但这样使用 W ...
- UWP中实现自定义标题栏
UWP中实现自定义标题栏 0x00 起因 在UWP开发中,有时候我们希望实现自定义标题栏,例如在标题栏中加入搜索框.按钮之类的控件.搜了下资料居然在一个日文网站找到了一篇介绍这个主题的文章: http ...
- 【Win10开发】自定义标题栏
UWP 现在已经可以自定义标题栏了,毕竟看灰色时间长了也会厌烦,开发者们还是希望能够将自己的UI做的更加漂亮,更加与众不同.那么废话不多说,我们开始吧! 首先要了解ApplicationViewTit ...
- Android开发-取消程序标题栏或自定义标题栏
注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 在Android开发中,跟据需要我们有时候需要自定义应用程序的标题栏或者取消程序的标题栏,下面本菜鸟在此记录与分享一下自己使用的方法 ...
随机推荐
- Unity中使用多构造函数
如果要实例化的类只有一个构造函数, 则使用方法很简单使用方法如下: 1 2 3 4 5 6 7 using (IUnityContainer container = new UnityContaine ...
- 淘宝的数据库拆分(TDDL)(转)
淘宝的数据拆分历程 系 统刚开始的时候,因为系统刚上线,用户不多,那个时候,所有的数据都放在了同一个数据库中,这个时候因为用户少压力小,一个数据库完全可以应付的了,但是 随着运营那些哥们辛苦的呐喊和拼 ...
- Zepto.js-Ajax 请求
Ajax 请求 执行Ajax请求.它可以是本地资源,或者通过支持HTTP access control的浏览器 或者通过 JSONP来实现跨域. 引入Ajax模块 <script src=&qu ...
- ThinkPHP 模板的包含、渲染、继承
一.模板包含 <include file="完整模板文件名" /> <include file="./Tpl/default ...
- Flex性能调优相关的一些总结
1.Performace包含4点:(1)Latency反应时间(2)Scalability:可伸缩性(3)Reliablity:稳定性(4)Availability:可用性2.运行时生命周期:Flex ...
- 关于GCD同步组实现多个异步线程的同步执行中的注意点
在App开发中经常会遇到多个线程同时向服务器取数据, 如果每个线程取得数据后都去刷新UI会造成界面的闪烁 也有可能出现部分数据还没有获取完毕造成程序crash 之前在网上看到很多是利用dispatch ...
- puppet的配置清单书写
puppet的配置清单书写 1使用数组,合并同类的 例如你想安装很多软件,如果分开来写的话,很麻烦,不简洁,这时我们可以使用数组来完成 以前我们这样来写 class packages{ package ...
- 走进React
走进React React是一个构建用户界面的JavaScript库,是Facebook公司在2013年5月在github上开源的.其特点如下: 高效--React通过对DOM的模拟,最大程度地减少和 ...
- 如何用CSS快速布局(一)—— 布局元素详细
要快速进行网页排版布局,则必须对布局的元素有清晰的了解,才不会总是在细节处出错.这一篇先详解有关布局的因素作为布局基础:块级元素and内联元素.盒模型.准确定位.元素对齐.样式继承.下一篇则重点描述快 ...
- 支付宝ios支付请求Java服务端签名报的一个错(ALI40247) 原创
今天做app的支付宝支付,遇到些问题,以前做支付宝支付签名都是直接在客户端App进行,今天下了最新版本ios的支付宝支付demo,运行demo时底部有红色的显眼字体,告知用户签名必须在服务端进行... ...