查看了下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. 《从零開始学Swift》学习笔记(Day 1)——我的第一行Swift代码

     Swift 2.0学习笔记--我的第一行Swift代码 原创文章,欢迎转载. 转载请注明:关东升的博客 当第一次看到以下代码时我石化了.这些代码是什么东东?单词拼出来的? import Foun ...

  2. QT学习记录之控件布局

    作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...

  3. javaScript_with用法

    with语句用途 暂时改变作用域链.简化代码. 语法结构 with(object){ //其他语句 } 例1 with(person){ name= "zhang"; addres ...

  4. Qt 学习: 视图选择 (QItemSelectionModel)

    博主QQ:1356438802 选择是视图中经常使用的一个操作.在列表.树或者表格中,通过鼠标点击能够选中某一项,被选中项会变成高亮或者反色.在 Qt 中,选择也是使用了一种模型.在 model/vi ...

  5. WPF实现控件拖动

    原文:WPF实现控件拖动 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lordwish/article/details/51823637 实现控件 ...

  6. tip of Firefox extention foxyproxy

    tip of Firefox extention foxyproxy

  7. WPF入门(三)->几何图形之矩形(RectangleGeometry)

    原文:WPF入门(三)->几何图形之矩形(RectangleGeometry) 我们可以使用RectangleGeometry来绘制一个矩形或者正方形 RectangleGeometry 类:描 ...

  8. Smart internet of things services

    A method and apparatus enable Internet of Things (IoT) services based on a SMART IoT architecture by ...

  9. WebHost failed to process a request.Memory gates checking failed because the free memory (140656640 bytes) is less than 5% of total memory

    WebHost failed to process a request. Sender Information: System.ServiceModel.ServiceHostingEnvironme ...

  10. Spring处理跨域请求

    [nio-8080-exec-8] o.s.web.cors.DefaultCorsProcessor        : Skip CORS processing: request is from s ...