查看了下MSDN发现Popup没有类拟Drag相关的属性和方法,第一时间想了thumb。忙了一会未果,就想起了强大的google。

发现中文资料很少,英文的发现有两篇很不错的,所以笔记在博客园里,希望对园里的朋友有用。

social.msdm

stackoverflow

楼主推荐使用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拖动的更多相关文章

  1. 《深入浅出WPF》笔记——资源篇

    原文:<深入浅出WPF>笔记--资源篇 前面的记录有的地方已经用到了资源,本文就来详细的记录一下WPF中的资源.我们平时的“资源”一词是指“资财之源”,是创造人类社会财富的源泉.在计算机程 ...

  2. 《深入浅出WPF》笔记——模板篇

    原文:<深入浅出WPF>笔记--模板篇 我们通常说的模板是用来参照的,同样在WPF中,模板是用来作为制作控件的参照. 一.认识模板 1.1WPF菜鸟看模板 前面的记录有提过,控件主要是算法 ...

  3. 转:【iOS开发每日小笔记(十一)】iOS8更新留下的“坑” NSAttributedString设置下划线 NSUnderlineStyleAttributeName 属性必须为NSNumber

    http://www.bubuko.com/infodetail-382485.html 标签:des   class   style   代码   html   使用   问题   文件   数据 ...

  4. 《深入浅出WPF》笔记——绘画与动画

    <深入浅出WPF>笔记——绘画与动画   本篇将记录一下如何在WPF中绘画和设计动画,这方面一直都不是VS的强项,然而它有一套利器Blend:这方面也不是我的优势,幸好我有博客园,能记录一 ...

  5. 小笔记:Timer定时间隔时间操作

    小笔记:Timer定时间隔时间操作,后面有时间再补充和完善: public class TimingSvc { /// <summary> /// 定时器,执行定时任务 /// </ ...

  6. 关于 linux中TCP数据包(SKB)序列号的小笔记

    关于  SKB序列号的小笔记 为了修改TCP协议,现在遇到了要改动tcp分组的序列号,但是只是在tcp_sendmsg函数中找到了SKB的end_seq  一直没有找到seq 不清楚在那里初始化了,就 ...

  7. Linux下postgres9.4 版本的单机版安装小笔记

    1.添加RPMyum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-redha ...

  8. WPF学习笔记-用Expression Design制作矢量图然后导出为XAML

    WPF学习笔记-用Expression Design制作矢量图然后导出为XAML 第一次用Windows live writer写东西,感觉不错,哈哈~~ 1.在白纸上完全凭感觉,想象来画图难度很大, ...

  9. WPF 学习笔记-在WPF下创建托盘图标

    原文:WPF 学习笔记-在WPF下创建托盘图标 首先需要在项目中引用System.Windows.Forms,System.Drawing; using System; using System.Co ...

随机推荐

  1. [Angular Directive] Build a Directive that Tracks User Events in a Service in Angular 2

    A @Directive is used to add behavior to elements and components in your application. This makes @Dir ...

  2. PHP怎么读写XML?(四种方法)

    PHP怎么读写XML?(四种方法) 一.总结 1.这四种方法中,字符串的方式是最原始的方法.SimpleXML和DOM扩展是属于基于树的解析器,把整个文档存储为树的数据结构中,需要把整个文档都加载到内 ...

  3. matplotlib油漆基础

    http://blog.csdn.net/pipisorry/article/details/37742423 matplotlib介绍 matplotlib 是python最著名的画图库,它提供了一 ...

  4. request.getSession().getServletContext().getRealPath()的一些坑

    今天是学校机房的服务器上对之前的一个网站升级时发现了一个bug,我自己的机器上用的tomcat8,机房上是tomcat7,结果一运行就开始报找不到文件,最后发现是文件分隔符的问题 原来在代码中涉及到路 ...

  5. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. CUDA atomic原子操作

    CUDA的原子操作可以理解为对一个变量进行"读取-修改-写入"这三个操作的一个最小单位的执行过程,这个执行过程不能够再分解为更小的部分,在它执行过程中,不允许其他并行线程对该变量进 ...

  7. visual studio 编译器在辨异 C/C++ 程序时的注意事项

    1. 数组大小的限制 visual studio 对数组的维数(元素的个数)没有限制,但要求数组的 size (sizeof() 后的结果,所占内存的大小)不得超过 0x7fff ffff = 2^3 ...

  8. [Linux] ssh秘钥对免密码登陆

    准备两台linux服务器 a和b , 在a上使用ssh命令登陆b服务器 , 并且不用 输入密码 1.在a服务器上,比如是root用户 ,进去/root/.ssh目录 ,没有就创建, 就是进入家目录的. ...

  9. springboot 配置多数据源 good

    1.首先在创建应用对象时引入autoConfig package com; import org.springframework.boot.SpringApplication; import org. ...

  10. Qt 的几个核心机制总结之 布局(QWidget可以设置setSizePolicy,而QSizePolicy有Fixed,minimum,maximum,preferred,expanding,ignore等7个属性,还可以横竖分开)

    1.Qt布局的作用 Qt的布局是通过布局管理器来实现的,布局管理器负责在父类窗口部件区域构建子窗口部件,使得放置在窗体中的每个窗口部件都有一个适合的大小和位置,并且能够随着应用程序本身的变化而变化从而 ...