WPF小笔记-Popup拖动
查看了下MSDN发现Popup没有类拟Drag相关的属性和方法,第一时间想了thumb。忙了一会未果,就想起了强大的google。
发现中文资料很少,英文的发现有两篇很不错的,所以笔记在博客园里,希望对园里的朋友有用。
楼主推荐使用social.msdm的方法,试过很好用:
<Popup Name="puSkills" Placement="MousePoint" PopupAnimation="Scroll" AllowsTransparency="True" IsEnabled="True" IsOpen="False">
<Border BorderBrush="DarkCyan" BorderThickness="3">
<StackPanel Background="AliceBlue" VerticalAlignment="Center" Height="400" Width="400">
<Label Name="lblCaption" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Blue" Background="Blue" MouseLeftButtonDown="lblCaption_MouseLeftButtonDown">Move</Label>
<StackPanel> <TextBlock HorizontalAlignment="Right">
Some Contents...........
</TextBlock>
</StackPanel>
</StackPanel>
</Border>
</Popup>
后台CS代码:
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(POINT Point);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(out POINT lpPoint);
[DllImportAttribute("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
private void lblCaption_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
POINT curPos;
IntPtr hWndPopup;
GetCursorPos(out curPos);
hWndPopup = WindowFromPoint(curPos);
ReleaseCapture();
SendMessage(hWndPopup, WM_NCLBUTTONDOWN, new IntPtr(HT_CAPTION), IntPtr.Zero);
}
Click the Move Content in label.. then move the mouse. Thank you!
WPF小笔记-Popup拖动的更多相关文章
- 《深入浅出WPF》笔记——资源篇
原文:<深入浅出WPF>笔记--资源篇 前面的记录有的地方已经用到了资源,本文就来详细的记录一下WPF中的资源.我们平时的“资源”一词是指“资财之源”,是创造人类社会财富的源泉.在计算机程 ...
- 《深入浅出WPF》笔记——模板篇
原文:<深入浅出WPF>笔记--模板篇 我们通常说的模板是用来参照的,同样在WPF中,模板是用来作为制作控件的参照. 一.认识模板 1.1WPF菜鸟看模板 前面的记录有提过,控件主要是算法 ...
- 转:【iOS开发每日小笔记(十一)】iOS8更新留下的“坑” NSAttributedString设置下划线 NSUnderlineStyleAttributeName 属性必须为NSNumber
http://www.bubuko.com/infodetail-382485.html 标签:des class style 代码 html 使用 问题 文件 数据 ...
- 《深入浅出WPF》笔记——绘画与动画
<深入浅出WPF>笔记——绘画与动画 本篇将记录一下如何在WPF中绘画和设计动画,这方面一直都不是VS的强项,然而它有一套利器Blend:这方面也不是我的优势,幸好我有博客园,能记录一 ...
- 小笔记:Timer定时间隔时间操作
小笔记:Timer定时间隔时间操作,后面有时间再补充和完善: public class TimingSvc { /// <summary> /// 定时器,执行定时任务 /// </ ...
- 关于 linux中TCP数据包(SKB)序列号的小笔记
关于 SKB序列号的小笔记 为了修改TCP协议,现在遇到了要改动tcp分组的序列号,但是只是在tcp_sendmsg函数中找到了SKB的end_seq 一直没有找到seq 不清楚在那里初始化了,就 ...
- Linux下postgres9.4 版本的单机版安装小笔记
1.添加RPMyum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-redha ...
- WPF学习笔记-用Expression Design制作矢量图然后导出为XAML
WPF学习笔记-用Expression Design制作矢量图然后导出为XAML 第一次用Windows live writer写东西,感觉不错,哈哈~~ 1.在白纸上完全凭感觉,想象来画图难度很大, ...
- WPF 学习笔记-在WPF下创建托盘图标
原文:WPF 学习笔记-在WPF下创建托盘图标 首先需要在项目中引用System.Windows.Forms,System.Drawing; using System; using System.Co ...
随机推荐
- [tmux] Share a tmux session for pair programming with ssh
By using ssh, you can share a tmux session, making pair programming much easier. We'll learn how to ...
- SpringMVC中跳转路径的问题
1. @RequestMapping 1)@RequestMapping既可以作用于类,也可以作用于方法 2)@RequestMapping中value值(即跳转的路径),可以加 "/&qu ...
- TensorFlow中卷积
CNN中的卷积核及TensorFlow中卷积的各种实现 声明: 1. 我和每一个应该看这篇博文的人一样,都是初学者,都是小菜鸟,我发布博文只是希望加深学习印象并与大家讨论. 2. 我不确定的地方用了“ ...
- 【u216】A+B Problem(aplusb)
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 对于给定的A和B,求A+B的值. [输入格式] 输入文件aplusb.in的第1行为一个整数A,第2行 ...
- SpringBoot JPA 专题
Error: Error starting ApplicationContext. To display the auto-configuration report re-run your appli ...
- 记录一下go web 文档
https://github.com/astaxie/build-web-application-with-golang
- VS2017 安装过程
2017 安装过程 工欲善其事必先利其器 Visual Studio 2017 正式版官方下载地址:https://www.visualstudio.com/downloads/ 安装vs2017的时 ...
- Hibernate综合问题
n + 1问题 query.iterate()信息返回迭代查询将开始发表声明:录ID语句 Hibernate: select student0_.id ascol_0_0_from t_student ...
- WPF 使用 SharpDX 在 D3DImage 显示
原文:WPF 使用 SharpDX 在 D3DImage 显示 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http://linde ...
- visual studio 编译器在辨异 C/C++ 程序时的注意事项
1. 数组大小的限制 visual studio 对数组的维数(元素的个数)没有限制,但要求数组的 size (sizeof() 后的结果,所占内存的大小)不得超过 0x7fff ffff = 2^3 ...