技术点:WPF的Behaviors实现了对象的行为附加,Microsoft.Expression.Interactions程序集中包含了若干Behaviors,其中MouseDragElementBehavior可以实现对象拖拽行为的附加,从而实现对象的拖拽功能。

代码如下:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp6"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="WpfApp6.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Label Content="拖我" HorizontalAlignment="Left" Margin="138.762,47.137,0,0" VerticalAlignment="Top">
<i:Interaction.Behaviors>
<ei:MouseDragElementBehavior/>
</i:Interaction.Behaviors>
</Label>
<Label Content="拖我" HorizontalAlignment="Left" Margin="252.741,89.735,0,0" VerticalAlignment="Top">
<i:Interaction.Behaviors>
<ei:MouseDragElementBehavior/>
</i:Interaction.Behaviors>
</Label>
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="22.862" Margin="59.322,159.513,0,0" VerticalAlignment="Top" Width="100">
<i:Interaction.Behaviors>
<ei:MouseDragElementBehavior/>
</i:Interaction.Behaviors>
</Border>
<Grid HorizontalAlignment="Left" Height="42.434" Margin="219.356,159.513,0,0" VerticalAlignment="Top" Width="111.513" Background="Black">
<i:Interaction.Behaviors>
<ei:MouseDragElementBehavior/>
</i:Interaction.Behaviors>
</Grid>
<Grid HorizontalAlignment="Left" Height="42.434" Margin="372.481,159.513,0,0" VerticalAlignment="Top" Width="111.513" Background="Black">
<i:Interaction.Behaviors>
<ei:MouseDragElementBehavior/>
</i:Interaction.Behaviors>
<Button Content="Button拖不了" HorizontalAlignment="Left" VerticalAlignment="Top" Width="91.709" Foreground="Black" Margin="9.804,13.194,0,0" Background="White">
</Button>
</Grid>
</Grid>
</Window>

运行效果:

代码

最新文章

  1. 解决jQuery多个版本,与其他js库冲突方法
  2. [Bundling and Minification ] 四、总结
  3. 【模式匹配】KMP算法的来龙去脉
  4. malloc和new的区别
  5. HDU 5113 Black And White 回溯+剪枝
  6. linux下验证码无法显示:Could not initialize class sun.awt.X1 解决方案
  7. aspcms标签使用经验
  8. Android开发中如何调用摄像头的功能
  9. OCP-1Z0-053-V12.02-501题 【转】
  10. Java消息队列-Spring整合ActiveMq
  11. ECMAScript 6 笔记(四)
  12. NDK 开发实例二(添加 Eigen库)
  13. [编织消息框架][JAVA核心技术]动态代理应用4
  14. PhotoShop CS6安装教程
  15. 白皮书之C++学习第一天
  16. 一般处理程序获取Session方式
  17. angularjs上传图片和文件
  18. 理解图像分割中的卷积(Understand Convolution for Semantic Segmentation)
  19. solr的认识、linux下安装、java下使用(含下载资源)
  20. 使用+Leapms查看线性规划的单纯形表,itsme命令

热门文章

  1. scala当中的对象
  2. android--简单的发短信功能
  3. cogs [HZOI 2015]有标号的二分图计数
  4. BZOJ4653:[NOI2016]区间(线段树)
  5. virtualbox+vagrant学习-4-Vagrantfile-7-WinRM Settings
  6. Go 测试单个方法
  7. 树莓派gitlab
  8. 到底什么是dp思想(内含大量经典例题,附带详细解析)
  9. linux内核netfilter连接跟踪的hash算法
  10. HTML小记