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