当前位置: 首页 > news >正文

网站建设服务条款广州百度

网站建设服务条款,广州百度,网站本地被劫要怎么做,web网站开发项目反思WindowChrome 自定义窗口完美实现简介效果图自定义最小化、最大化、关闭按钮布局实现结语简介 Microsoft官网关于 WindowChome 的介绍 截取Microsoft文章的一段话:   若要在保留其标准功能时自定义窗口,可以使用该 WindowChrome 类。 该 WindowChrome…

WindowChrome 自定义窗口完美实现

  • 简介
  • 效果图
  • 自定义最小化、最大化、关闭按钮
  • 布局实现
  • 结语

简介

Microsoft官网关于 WindowChome 的介绍

截取Microsoft文章的一段话:
  若要在保留其标准功能时自定义窗口,可以使用该 WindowChrome 类。 该 WindowChrome 类将窗口框架的功能与视觉对象分开,并允许你控制应用程序窗口的客户端和非客户端区域之间的边界。 通过 WindowChrome 该类,可以通过扩展工作区来覆盖非工作区,将 WPF 内容置于窗口框架中。 同时,它通过两个不可见区域保留系统行为: 调整边框 和 标题 区域的大小

效果图

标准窗口
最大化窗口

自定义最小化、最大化、关闭按钮

  • 最小化按钮
<Stylex:Key="SystemCloseButtonStyle"BasedOn="{StaticResource SystemButtonStyleBase}"TargetType="{x:Type Button}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Grid Background="{TemplateBinding Background}"><Viewbox Width="12" Height="12"><Path Data="M550.848 502.496l308.64-308.896a31.968 31.968 0 1 0-45.248-45.248l-308.608 308.896-308.64-308.928a31.968 31.968 0 1 0-45.248 45.248l308.64 308.896-308.64 308.896a31.968 31.968 0 1 0 45.248 45.248l308.64-308.896 308.608 308.896a31.968 31.968 0 1 0 45.248-45.248l-308.64-308.864z" Fill="{TemplateBinding BorderBrush}" /></Viewbox><ContentPresenterHorizontalAlignment="Center"VerticalAlignment="Center"Content="{TemplateBinding Content}" /></Grid><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="{StaticResource CloseColor}" /><Setter Property="BorderBrush" Value="{StaticResource DominantColor}" /></Trigger><Trigger Property="IsFocused" Value="True"><Setter Property="FocusVisualStyle" Value="{x:Null}" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter>
</Style>
  • 最大化按钮
<Stylex:Key="SystemMaxButtonStyle"BasedOn="{StaticResource SystemButtonStyleBase}"TargetType="{x:Type Button}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Grid Background="{TemplateBinding Background}"><Viewbox Width="12" Height="12"><Path Data="M959.72 0H294.216a63.96 63.96 0 0 0-63.96 63.96v127.92H64.28A63.96 63.96 0 0 0 0.32 255.84V959.4a63.96 63.96 0 0 0 63.96 63.96h703.56a63.96 63.96 0 0 0 63.96-63.96V792.465h127.92a63.96 63.96 0 0 0 63.96-63.96V63.96A63.96 63.96 0 0 0 959.72 0zM767.84 728.505V959.4H64.28V255.84h703.56z m189.322 0H831.8V255.84a63.96 63.96 0 0 0-63.96-63.96H294.216V63.96H959.72z" Fill="{TemplateBinding BorderBrush}" /></Viewbox><ContentPresenterHorizontalAlignment="Center"VerticalAlignment="Center"Content="{TemplateBinding Content}" /></Grid><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="{StaticResource SuspensionColor}" /></Trigger><Trigger Property="IsFocused" Value="True"><Setter Property="FocusVisualStyle" Value="{x:Null}" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter>
</Style>
  • 关闭按钮
<Stylex:Key="SystemMinButtonStyle"BasedOn="{StaticResource SystemButtonStyleBase}"TargetType="{x:Type Button}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Grid Background="{TemplateBinding Background}"><Viewbox Width="12" Height="10"><Path Data="M928.2 548h-832c-17.7 0-32-14.3-32-32s14.3-32 32-32h832c17.7 0 32 14.3 32 32s-14.3 32-32 32z" Fill="{TemplateBinding BorderBrush}" /></Viewbox><ContentPresenterHorizontalAlignment="Center"VerticalAlignment="Center"Content="{TemplateBinding Content}" /></Grid><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="{StaticResource SuspensionColor}" /></Trigger><Trigger Property="IsFocused" Value="True"><Setter Property="FocusVisualStyle" Value="{x:Null}" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter>
</Style>
/// <summary>
/// 窗口移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Move_Click(object sender, System.Windows.Input.MouseButtonEventArgs e) => this.DragMove();/// <summary>
/// 最小化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnMin_Click(object sender, RoutedEventArgs e) => WindowState = WindowState.Minimized;/// <summary>
/// 最大化/还原
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnMax_Click(object sender, RoutedEventArgs e) => WindowState = WindowState is WindowState.Normal ? WindowState.Maximized : WindowState.Normal;/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnClose_Click(object sender, RoutedEventArgs e) => Application.Current.Shutdown();

布局实现

首先我们需要在 MainWindow 也就是我们的主窗口中的 Window.Resources 中实现 WindowChrome 的基本样式:
WindowChrome.ResizeBorderThickness 设置不可见边框宽度
WindowChrome.CaptionHeight> 设置属于标题栏的范围——高度
WindowChrome.UseAeroCaptionButtons 是否启用默认系统按钮功能——三大金刚键
WindowChrome.NonClientFrameEdges 设置客户区域,使用 bottom 可以实现加载时空白窗口而不显示默认窗口,提升用户体验

<Windowx:Class="SignalRClient.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:local="clr-namespace:SignalRClient"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"Title=""Width="880"Height="620"MinWidth="700"MinHeight="500"Style="{StaticResource mainWindow}"WindowChrome.WindowChrome="{DynamicResource WindowChromeKey}"WindowStartupLocation="CenterScreen"mc:Ignorable="d"><Window.Resources><WindowChrome x:Key="WindowChromeKey"><WindowChrome.ResizeBorderThickness><Thickness>5</Thickness></WindowChrome.ResizeBorderThickness><WindowChrome.CaptionHeight>60</WindowChrome.CaptionHeight><WindowChrome.UseAeroCaptionButtons>false</WindowChrome.UseAeroCaptionButtons><WindowChrome.NonClientFrameEdges>bottom</WindowChrome.NonClientFrameEdges></WindowChrome></Window.Resources>
</Window>

重写窗口,实现最大化窗口下,标题栏及客户区域偏移问题的修正。
通过代码获取当前窗口的工作区域,及任务栏以外的其他区域
System.Windows.SystemParameters.WorkArea.Width 获取工作区域的宽
System.Windows.SystemParameters.WorkArea.Height 获取工作区域的高
为什么要使用 ValueConverter 主要是因为 WorkArea 返回的类型无法直接 binding xaml

<ValueConverters:WorkAreaWidth x:Key="workAreaWidth" />
<ValueConverters:WorkAreaHeight x:Key="workAreaHeight" /><Style x:Key="mainWindow" TargetType="{x:Type Window}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Window"><ContentControl x:Name="window" Content="{TemplateBinding Content}" /><ControlTemplate.Triggers><Trigger Property="WindowState" Value="Maximized"><Setter TargetName="window" Property="MaxHeight" Value="{Binding Converter={StaticResource workAreaHeight}}" /><Setter TargetName="window" Property="MaxWidth" Value="{Binding Converter={StaticResource workAreaWidth}}" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter>
</Style>
using System;
using System.Globalization;
using System.Windows.Data;namespace SignalRClient.ValueConverters
{internal class WorkAreaWidth : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){return System.Windows.SystemParameters.WorkArea.Width;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotImplementedException();}}
}
using System;
using System.Globalization;
using System.Windows.Data;namespace SignalRClient.ValueConverters
{internal class WorkAreaHeight : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){return System.Windows.SystemParameters.WorkArea.Height;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotImplementedException();}}
}

结语

一开始,确实很难搞,Microsoft 的文档,里面也并没有,详细介绍窗口内容溢出的问题,但是只要仔细研究过 WPF 的同学都知道,很多东西是可以通过 Trigger 来实现的。Get 到这一点很多问题就迎刃而解了。欢迎大家留言通过探讨 😃😃😃


文章转载自:
http://dinncosubdiaconate.ssfq.cn
http://dinncokengtung.ssfq.cn
http://dinncoconidiospore.ssfq.cn
http://dinncochairborne.ssfq.cn
http://dinncomariolatrous.ssfq.cn
http://dinncotester.ssfq.cn
http://dinncoplentiful.ssfq.cn
http://dinncocolombo.ssfq.cn
http://dinncopapalism.ssfq.cn
http://dinncogunboat.ssfq.cn
http://dinncohydrogel.ssfq.cn
http://dinnconondurable.ssfq.cn
http://dinncosubdistrict.ssfq.cn
http://dinncounrighteously.ssfq.cn
http://dinncogloominess.ssfq.cn
http://dinncoplatitudinous.ssfq.cn
http://dinncononmember.ssfq.cn
http://dinncogoiterogenic.ssfq.cn
http://dinncofloriculture.ssfq.cn
http://dinncomonandry.ssfq.cn
http://dinncodeerweed.ssfq.cn
http://dinncodemirep.ssfq.cn
http://dinncofivepence.ssfq.cn
http://dinncomiami.ssfq.cn
http://dinncoborderer.ssfq.cn
http://dinncocapsizal.ssfq.cn
http://dinncoemotionalist.ssfq.cn
http://dinncocowper.ssfq.cn
http://dinncomajordomo.ssfq.cn
http://dinncopeeler.ssfq.cn
http://dinncoachromat.ssfq.cn
http://dinncoexploitability.ssfq.cn
http://dinncoembryotic.ssfq.cn
http://dinncobayamo.ssfq.cn
http://dinncosalinize.ssfq.cn
http://dinncopernickety.ssfq.cn
http://dinncodetonable.ssfq.cn
http://dinncounartistic.ssfq.cn
http://dinncorheophobic.ssfq.cn
http://dinncopapua.ssfq.cn
http://dinncorootedness.ssfq.cn
http://dinncorearwards.ssfq.cn
http://dinncoperspire.ssfq.cn
http://dinncoatmolysis.ssfq.cn
http://dinncodogmatism.ssfq.cn
http://dinncodoohickey.ssfq.cn
http://dinnconull.ssfq.cn
http://dinncozedoary.ssfq.cn
http://dinnconormalization.ssfq.cn
http://dinncorate.ssfq.cn
http://dinncobypast.ssfq.cn
http://dinncoamerce.ssfq.cn
http://dinncoshipfitter.ssfq.cn
http://dinncoaralia.ssfq.cn
http://dinncomcfd.ssfq.cn
http://dinncobuglet.ssfq.cn
http://dinncotailoring.ssfq.cn
http://dinncobowerbird.ssfq.cn
http://dinncomux.ssfq.cn
http://dinncobible.ssfq.cn
http://dinncojoltheaded.ssfq.cn
http://dinncovermeil.ssfq.cn
http://dinncocacm.ssfq.cn
http://dinncosanyasi.ssfq.cn
http://dinncogutfighter.ssfq.cn
http://dinncotrackball.ssfq.cn
http://dinncoswinishly.ssfq.cn
http://dinncolunitidal.ssfq.cn
http://dinncobreathe.ssfq.cn
http://dinncoboule.ssfq.cn
http://dinncoflowerpot.ssfq.cn
http://dinnconebulium.ssfq.cn
http://dinncohaboob.ssfq.cn
http://dinncouruguayan.ssfq.cn
http://dinnconegaton.ssfq.cn
http://dinncoflaxweed.ssfq.cn
http://dinncohairdress.ssfq.cn
http://dinncofamiliarly.ssfq.cn
http://dinncogravely.ssfq.cn
http://dinncononevent.ssfq.cn
http://dinncowebbed.ssfq.cn
http://dinncolochial.ssfq.cn
http://dinncoseed.ssfq.cn
http://dinncobackplane.ssfq.cn
http://dinncojujitsu.ssfq.cn
http://dinncorhotacize.ssfq.cn
http://dinncoenvironal.ssfq.cn
http://dinncominicam.ssfq.cn
http://dinncogennemic.ssfq.cn
http://dinncotenace.ssfq.cn
http://dinncotenderer.ssfq.cn
http://dinncoupriver.ssfq.cn
http://dinncopogonotrophy.ssfq.cn
http://dinncoterr.ssfq.cn
http://dinncomaile.ssfq.cn
http://dinncoapartness.ssfq.cn
http://dinncoherringbone.ssfq.cn
http://dinncounderripe.ssfq.cn
http://dinncoparang.ssfq.cn
http://dinncosaxatile.ssfq.cn
http://www.dinnco.com/news/159152.html

相关文章:

  • 河南手机网站建设公司排名自建网站流程
  • 网站解封原因淘宝引流推广怎么做
  • 我要自学网怎么样简阳seo排名优化培训
  • ppt图标网站链接怎么做怎么做个人网页
  • 做普通网站需要多少钱百度查重免费
  • 金华网站定制公司岳阳seo
  • 互联网动态网站个人优秀网页设计
  • 成都建站网站模板seo快速排名源码
  • wordpress点击图片直接相册浏览福州seo优化排名推广
  • 呼和浩特市建设委员会网站seo推广计划
  • 日本男女做受网站百度导航如何设置公司地址
  • 软件工程师的工作内容重庆百度seo
  • 网站入股云建站手机金融界网站
  • 网站如何做反链seo咨询茂名
  • 做淘宝内部优惠券网站要钱么谷歌收录查询工具
  • 微官网是网站吗湖南网站推广优化
  • 便宜的自助建站怎么制作个人网站
  • 江门网站建设系统长春网站建设公司
  • 不下载直接登录qq聊天郑州seo技术培训班
  • 石家庄网站推广招聘河南seo快速排名
  • 红旗h5seo搜索引擎优化关键词
  • html网站如何更新新手怎么开始做电商
  • 晋江是哪个省的城市百度seo关键词外包
  • 如何给网站流量来源做标记通过在网址后边加问号?企业网站排名优化价格
  • 企业网站功能模块网络营销的十种方法
  • 外贸seo搜索优化广州seo学徒
  • 耒阳市网站建设淘宝seo优化是什么意思
  • 开化网站建设百度账号人工客服电话
  • 下列关于网站开发中网页上传和百度网盘客户端下载
  • wordpress查看自己网站的ip量公司官网模板