转载自:
https://blog.csdn.net/lisenyang/article/details/18231195
https://www.bilibili.com/video/av38011236/?p=30
在xaml文件中使用自己在本项目中创建的类
使用上图的类:
代码
<Window x:Class="WpfApplication23.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"//
xmlns:custom="clr-namespace:WpfApplication23"//
Title="MainWindow" Height="350" Width="525">
<Ellipse Fill="Blue" Height="80" Canvas.Left="80" Stroke="Red" Canvas.Top="70" Width="80">
<i:Interaction.Behaviors>//
<custom:DragInCanvasBehavior>//
</custom:DragInCanvasBehavior>
</i:Interaction.Behaviors>
</Ellipse>