使用WindowChrome在WPF窗口上显示默认窗口按钮
发布时间:2020-12-14 01:35:32 所属栏目:Windows 来源:网络整理
导读:我发现在 WPF窗口上使用WindowChrome可以让我在窗口中的任何地方放置内容,这是一个很好的想法.现在我终于可以使标题栏与我的应用程序的其余部分具有相同的颜色. 但是,我仍然喜欢非样式窗口上显示的默认最小化/最大化/关闭按钮. 有没有什么办法可以使用Window
我发现在
WPF窗口上使用WindowChrome可以让我在窗口中的任何地方放置内容,这是一个很好的想法.现在我终于可以使标题栏与我的应用程序的其余部分具有相同的颜色.
但是,我仍然喜欢非样式窗口上显示的默认最小化/最大化/关闭按钮. 有没有什么办法可以使用WindowChrome设置窗口样式但仍保留默认按钮? <Style x:Key="MainWindow" TargetType="{x:Type Window}"> <Setter Property="WindowChrome.WindowChrome"> <Setter.Value> <WindowChrome CaptionHeight="30" ResizeBorderThickness="5" /> </Setter.Value> </Setter> </Style> <Window Style="{StaticResource MainWindow}"> <Grid Background="Black"> <MyContent /> </Grid> </Window> 这会产生一个很大的黑色窗口(太棒了!),但没有任何最小/最大/关闭按钮,因为它们隐藏在网格后面(不太好).按钮仍然是可点击的,所以它们显然在那里. 解决方法
不,我不这么认为.您可以将GlassFrameThickness属性设置为0以禁用按钮,然后您将不得不创建自己的自定义按钮.您可以参考以下项目中的一些示例:https://wpfwindow.codeplex.com/. 如果你想要Window 10风格的标题按钮,你可以使用Segoe MDL2 Assets字体系列: <Style x:Key="CaptionButtonStyle" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid x:Name="LayoutRoot" Background="Transparent" Width="44" Height="30"> <TextBlock x:Name="txt" Text="{TemplateBinding Content}" FontFamily="Segoe MDL2 Assets" FontSize="10" Foreground="#999999" HorizontalAlignment="Center" VerticalAlignment="Center" RenderOptions.ClearTypeHint="Auto" TextOptions.TextRenderingMode="Aliased" TextOptions.TextFormattingMode="Display"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouSEOver" Value="True"> <Setter TargetName="LayoutRoot" Property="Background" Value="#E5E5E5"/> <Setter TargetName="txt" Property="Foreground" Value="#000000"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="MinimizeButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}"> <Setter Property="Content" Value=""/> </Style> <Style x:Key="MaximizeButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}"> <Setter Property="Content" Value=""/> </Style> <Style x:Key="RestoreButtonStyle" TargetType="Button" BasedOn="{StaticResource CaptionButtonStyle}"> <Setter Property="Content" Value=""/> </Style> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 用于Windows的Git bash不提示输入密码
- windows – 设置rhc时出错(红帽客户端工具)
- 批处理文件 – Windows 2008服务器任务调度程序不运行.bat批
- windows-server-2008 – HTTP错误503.该服务不可用.在带有i
- Windows Azure和Amazon AWS之间的站点到站点VPN
- 批处理文件 – (Windows批处理)如果块中的Goto行为非常奇怪
- 在Windows中运行/调试python程序的最简单的方法
- windows-server-2008 – 有没有办法从命令行/ Powershell显
- 打印 – 如何使用fmt在Go中打印出常量uint64?
- 全屏显示窗体
推荐文章
站长推荐
- windows-server-2012 – 如何解决Windows Server
- haskell – 仅从全屏浮动窗口中移除边框(XMonad配
- windows-7 – 如何让Windows 7将与子网的VPN连接
- windows – 64位系统上32位应用程序的内存分配限
- Windows上的python 2.7 vs 2.6速度
- 身份验证–Windows Phone 10 Google Web授权代理
- 如何在Windows窗体应用程序中使用C#.NET正确实现
- windows-server-2008 – 按需病毒扫描Windows
- windows-server-2003 – 如何转发Windows DNS服务
- iis – 经典管道模式下的Windows Identity Found
热点阅读