添加没有标题栏的WPF窗口,但需要在xaml文件中鼠标悬停时显示它

编程入门 行业动态 更新时间:2024-10-28 12:23:16
本文介绍了添加没有标题栏的WPF窗口,但需要在xaml文件中鼠标悬停时显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试使用删除标题栏WindowStyle =无 但我需要显示并通过鼠标悬停WPF中的标题栏。那么如何在xaml代码中继续执行此操作?

解决方案

您好, 您可以使用 MouseLeave 和 MouseEnter 事件,但是当您将光标移动到标题栏附近时,此解决方案将产生波动。因此,我建议您使用 Mahapps.Metro - WPF的UI工具包 。它为WPF窗口提供扩展属性。请按照上述链接中提供的步骤操作。 并将两个事件 MouseLeave MouseEnter 添加到WPF窗口。在相应的活动中使用以下代码。 MouseEnter 事件:

private void Window_MouseEnter( object sender,MouseEventArgs e ) { this .ShowTitleBar = true ; this .ShowCloseButton = true ; this .ShowMinButton = true ; this .ShowMaxRestoreButton = true ; }

MouseLeave 事件:

private void Window_MouseEnter( object sender,MouseEventArgs e) { this .ShowTitleBar = false ; this .ShowCloseButton = false ; this .ShowMinButton = false ; this .ShowMaxRestoreButton = false ; }

现在,将以下属性添加到xaml中的WPF窗口,

< 控件:metrowindow x:class = CP1038562.MainWindow xmlns = schemas.microsoft/winfx/2006/xaml / presentation xmlns:x = schemas.microsoft/winfx/2006/xaml xmlns:Controls = clr-namespace:MahApps.Metro.Controls; assem bly = MahApps.Metro 标题 = MainWindow ShowTitleBar = False ShowMaxRestoreButton = False ShowMinButton = False ShowCloseButton = False 高度 = 350 宽度 = 525 MouseEnter = Window_MouseEnter BorderBrush = 蓝色 BorderThickness = 2 MouseLeave = Window_MouseLeave > < / Controls:metrowindow >

Build&运行

I tried with removing title bar using WindowStyle="None" But I need to to show and hide the title bar in WPF by mouse over. So how can I proceed to do this in xaml code?

解决方案

Hi, You can achieve this using MouseLeave and MouseEnter events of the WPF Window, But this solution will create a fluctuation when you move cursor near to title bar. So I suggest you to use Mahapps.Metro - a UI toolkit for WPF. It provides extended properties for WPF window. Follow the steps provided in the above link. And Add two events MouseLeave, MouseEnter to the WPF window. Use the below code in respective events. MouseEnter event:

private void Window_MouseEnter(object sender, MouseEventArgs e) { this.ShowTitleBar = true; this.ShowCloseButton = true; this.ShowMinButton = true; this.ShowMaxRestoreButton = true; }

MouseLeave event:

private void Window_MouseEnter(object sender, MouseEventArgs e) { this.ShowTitleBar = false; this.ShowCloseButton = false; this.ShowMinButton = false; this.ShowMaxRestoreButton = false; }

Now, Add Following properties to the WPF window in xaml,

<Controls:metrowindow x:class="CP1038562.MainWindow" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" Title="MainWindow" ShowTitleBar="False" ShowMaxRestoreButton="False" ShowMinButton="False" ShowCloseButton="False" Height="350" Width="525" MouseEnter="Window_MouseEnter" BorderBrush="Blue" BorderThickness="2" MouseLeave="Window_MouseLeave"> </Controls:metrowindow>

Build & Run.

更多推荐

添加没有标题栏的WPF窗口,但需要在xaml文件中鼠标悬停时显示它

本文发布于:2023-11-10 01:28:26,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:鼠标   标题栏   窗口   文件   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!