Okay, so here's where we have to put away the Windows Forms mentality (heh). In WPF you need to think about the separation between functionality and appearance. That is, you allow your code (c#) to determine the functionality aspect, and then do some templating in xaml to give it the appearance.
The functionality you actually want is that of a Thumb. A thumb already has the dragging functionality built into it, so you just need to create a template to give it it's appearance.
First take a look at this:
http://wpf.2000things.com/tag/dragging/
I would approach this by creating your own class that derives from thumb like this:
// Although the visual template we're applying is a circle,
// the FUNCTIONALITY is primarily that of a thumb. So that's what
// we'll use. A thumb is essentially a 'draggable thing'.
class DragCircle : System.Windows.Controls.Primitives.Thumb
{
public DragCircle()
{
// Thumbs _track_ movement, but they don't actually move. We have to handle this ourselves.
// We do this by setting the Canvas.Left/Canvas.Top attached properties. Of course, for this
// to work our DragCircle has to be placed on a Canvas, otherwise there's no-one to read the property.
// IMPORTANT! In order to read the Canvas position later, it needs to have a record in the WPF
// dependency property table. So for now we'll just set it to '0' as a default.
Canvas.SetLeft (this, 0);
Canvas.SetTop (this, 0);
// The drag-delta event occurs when the Thumb is dragged. 'delta' represents "change" just like
// we all learned in calculus.
this.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(DragCircle_DragDelta);
}
void DragCircle_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
// Read the Canvas location from the WPF database.
Double currentX = Canvas.GetLeft(this);
Double currentY = Canvas.GetTop(this);
// Now update the canvas attached properties using the drag-delta ('change in position').
// Note that Canvas.SetLeft is just a helper function that maps to the attached property:
// this.SetValue(Canvas.TopProperty, SOME_VALUE);
Canvas.SetLeft(this, currentX + e.HorizontalChange);
Canvas.SetTop(this, currentY + e.VerticalChange);
}
}
Then just createa template like this:
<Window.Resources>
<Style TargetType="lol:DragCircle">
<Setter Property="Foreground" Value="LightGreen" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="lol:DragCircle">
<Ellipse Width="20" Height="20" Fill="{TemplateBinding Foreground}" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
Now drop it onto a canvas, and you're done.
<Canvas>
<lol:DragCircle Canvas.Left="100" Canvas.Top="200" />
<lol:DragCircle Canvas.Left="50" Canvas.Top="50" />
<lol:DragCircle Canvas.Left="300" Canvas.Top="400" />
</Canvas>