在wpf中的窗口标题栏上双击事件(double click event on window title bar in wpf)

   IT问题网   2020-06-30 00:00:00

问 题

我想在标题栏上实现双击事件以最大化并最小化窗口(下面的xaml)



 lt;  窗口  

xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x =" http://schemas.microsoft.com/winfx / 2006 / xaml"

xml:lang =" en-us"

xmlns:abc =" clr-namespace:abc"

xmln s:d =" http://schemas.microsoft.com/expression/blend/2006"

xmlns:mc =" http://schemas.openxmlformats.org/markup-兼容性/ 2006"

mc:可忽略 =" d"

xmlns:local =" clr-namespace:abc"

x:class =" abc.window1"

x:name =" 窗口"

标题 =" 好人"

minheight =" 100"

minwidth =" 200" 允许透明度 =" true" 背景 =" 透明" sizechanged =" window_sizechanged"

高度 =" 600" 宽度 =" 900" windowstyle =" 无" 已加载 =" window_loaded" previewmousemove =" resetcursor"

resizemode =" noresize" windowstartuplocation =" centerscreen" 图标 =" / abc; component / aexe.ico" previewkeydown =" window_previewkeydown" mouseleftbuttondown =" window_mousedown" gt;


lt; 边框 名称 =" windowborder1" borderbrush =" {dynamicresource mydarkbluesolidbrush}" 背景 =" {dynamicresource titleborderbrush}" borderthickness =" 1.5" cornerradius =" 5" gt;

lt; 边框 名称 =" windowborder" borderbrush =" {staticresource titleborderbrush}" 背景 =" {staticresource titleborderbrush}" borderthickness =" 2" cornerradius =" 5" gt;

lt; 网格 x:名称 =" layoutroot" gt;

lt; 矩形 填充 =" {staticresource titleborderbrush}" 笔划 =" {x :null}" verticalalignment =" 顶部" 高度 =" 2.5" x:名称 =" top" previewmousedown =" 调整大小" mousemove =" displayresizecursor" 保证金 =" 2.5,0,2.5,0" / gt;
lt; 矩形 填充 =" {staticresource titleborderbrush}" 笔划 =" {x:null}" x:名称 =" bottom" 高度 =" 2.5" verticalalignment =" 底部" previewmousedown =" 调整大小" mousemove =" displayresizecursor" 保证金 =" 2.5,0,2.5,0" / gt;
lt; 矩形 填写 =" {staticresource titleborderbrush}" 笔划 =" {x:null} " horizontalalignment =" 左" 保证金 =" 0,2.5,0,2.5" 宽度 =" 2.5" x:名称 =" left" previewmousedown =" 调整大小" mousemove =" displayresizecursor" / gt;
lt; 矩形 填充 =" {staticresource titleborderbrush}" stroke =" {x:null}" 保证金 =" 0,2.5,0,2.5" 宽度 =" 2.5" horizontalalignment =" 右" x:名称 =" right" previewmousedown =" 调整大小" mousemove =" displayresizecursor" / gt;
lt; 矩形 填充 =" {staticresource titleborderbrush}" 笔划 =" {x:null}" horizontalalignment = " 左" verticalalignment =" 底部" 宽度 =" 2.5" 高度t =" 2.5" x:名称 =" bottomleft" previewmousedown =" 调整大小" mousemove =" displayresizecursor" / gt;
lt; 矩形 填充 =" {staticresource titleborderbrush}" 笔划 =" {x:null}" verticalalignment =" 底部" 高度 =" 2.5" 宽度 =" 2.5" horizontalalignment =" 右" x:名称 =" bottomright" previewmousedown =" 调整大小" mousemove =" displayresizecursor" / gt;
lt; 矩形 填充 =" {staticresource titleborderbrush}" 描边 =" {x:null}" horizontalalignment =" 右" 宽度 =" 2.5" 高度 =" 2.5" verticalalignment =" top" x:名称 =" topright" previewmousedown =" 调整大小" mousemove =" displayresizecursor" / gt;
lt; 矩形 填充 =" {staticresource titleborderbrush}" 笔划 =" {x:null}" horizontalalignment = " 左" 宽度 =" 2.5" verticalalignment =" top" 高度 =" 3" x:名称 =" topleft" previewmouseleftbuttondown =" 调整大小" mousemove =" displayresizecursor" / gt;

lt;! - 顶级专家组 - gt;

lt; dockpanel 名称 =" maindocpanal" 背景 =" {dynamicresource titleborderbrush}" 保证金 =" 2.5,2.5,2.5,2.5" gt;

lt; 网格 高度 =" auto" 名称 =" gridtitle" 宽度 =" auto" dockpanel.dock =" top" mouseleftbuttondown =" mouseleftbuttondown" 保证金 =" 0,0,0,0" gt;


lt;! - title bar - gt;

lt; 网格 名称 =" maxminclosegrid" 高度 =" auto" 背景 =" {dynamicresource titleborderbrush}"

cliptobounds =" false" 保证金 =" 0,0,0,0" ishittestvisible =" true" gt;
lt; grid.columndefinitions gt;
lt; columndefinition 宽度 =" 。300 *" / gt;
lt; columndefinition 宽度 =" 。700 *" / gt;
lt; / grid.columndefinitions gt;

lt; 标签 保证金 =" 105,5,0,1" 姓名 =" titlelabel" dockpanel.dock =" 热门"

背景 =" 透明" cliptobounds=\"false\" foreground=\" {dynamicresource mydarkbluesolidbrush}\" fontfamily=\"tahoma\"

grid.column=\"1\" horizontalalignment=\"left\" width=\"185\" fontsize=\"14\" fontstyle=\"normal\"

gt;abc
lt;/labelgt;
lt;/gridgt;
lt;!-- title bar --gt;
lt;/dockpanelgt;
lt;!-- top panel --gt;
lt;/gridgt;
lt;/bordergt;
lt;/bor dergt;

lt;/windowgt;

解决方案

hi
you can use the following event in the xaml:

previewmousedoubleclick=\"window_previewmousedoubleclick\"




you don’’t have to put it on the \"window\". you can create your own title bar in the top and add the event to that control instead. because adding it to the window make it work all over the window.



then add the following code in the event:

private void window_previewmousedoubleclick(object sender, mousebuttoneventargs e) 
{
if (this.windowstate == system.windows.windowstate.maximized)
this.windowstate = system.windows.windowstate.minimized;
else
this.windowstate = system.windows.windowstate.maximized;
}




this method will maximize if not yet maximized, and minimize if maximized.



hope it helped :-)

标签:中的窗口标题栏双击事件



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

批处理文件可以保留在内存中(Can Batch File Hold In Memory)

problem i was wondering...... i have a batch ...

用于在C ++中的开源PDF库中读取PDF文件的代码(Code for reading a PDF file in Open Source PDF Libraries in C++)

problem i want the code for reading a pdf file and store ...

MFC应用程序中RichEdit控件的问题(Problem with RichEdit control in MFC application)

problem in my application i am using crichedi ...

如何为每个IP地址创建线程?(How to create threads to each Ip address)

problem good morning friends, i am currently ...

职业生涯在DotNet中呼唤我(Career Call for Me In DotNet)

problem hi all, i''m working as software eng from past o ...

从应用程序备份数据库(take backup of database from application)

problem hi all, i have a database named mydb ...

如何在客户端系统中维护我们的数据库(how to maintain our database in client system)

problem hello iam developing windows application and my ...

C#发送电子邮件SMTP问题(C# sending email SMTP problems)

problem dears i am using visual studio 2008 3 ...

需要帮助使用opengl在c ++中构建迷宫(Need help in building maze in c++ using opengl)

problem this is my code for solution path, i used random ...

使用文本框将一个选项卡值添加到另一个选项卡。(one tab value to another tab both using text box.)

problem how to assign one tab value to another tab if bot ...

使用WSAsy-Model的Win32套接字(Win32 Socket using WSAsy-Model)

problem hi !i want to use the wsaasyncselect ...

一次单击添加空白记录(one click add blank record)

problem dear sir, when was clicking edit link button ther ...

关于sql'列表的问题(the problem which is about listing of sql')

problem i want to get 3 datas which has been added lastly ...

DataGridView绑定源datacontext.ExecuteQuery allowusertoaddrows已禁用(DataGridView Binding Source datacontext.ExecuteQuery allowusertoaddrows disabled)

problem using the following code: iqueryable data = db.e ...

我想在每个页面上显示用户名(I want to display username on every page)

problem can i use loginview control without login control ...

解释如何重载.ToString()方法......(Explain how to overload .ToString() method...)

problem help me friends... :) thanks in advance... soluti ...

UserControl编辑对象(UserControl to edit an object)

problem hello, i have a usercontrol that has some fields ...

使用任何网络服务获取英国的邮政编码和地址(get postal code and address of UK using any web service)

problem hi, i have 2 text box. 1 for u.k. p ...

Windows 7的应用程序(application for windows 7)

problem do i need to install anything to program an app u ...

将控件添加到datagridview(add control to datagridview)

problem hi, there is a control called nbtext (which forma ...