Directory Freebies VS CheatSheet Forum

RSS

Email

Translate

Home About Archive Privacy Contact Advertise Write for Dev102

Hi.

 

As the Headline says, I will show you how to make a Drag and Drop / Move Content control. for this example I will use a canvas and an Image. But you can easily make it more generic by using a Content Control instead of the image.

 

It is actually very simple, let’s start with the Xaml Code.

   1: <Canvas Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" HorizontalAlignment="Stretch" 
   2:         VerticalAlignment="Stretch" x:Name="ImageHolder" >
   3:     <Image Canvas.Left="0" MouseWheel="Img_MouseWheel" MouseMove="Img_MouseMove" 
   4:            MouseDown="Img_MouseDown" MouseUp="Img_MouseUp" Panel.ZIndex="0" 
   5:            Cursor="Hand" Canvas.Top="0" Height="150" Width="150" Source="sketch.jpg" 
   6:            x:Name="Img">
   7:     </Image>
   8: </Canvas>

As you can see we are using a canvas and an Image.

 

Implementing Drag and Move

to implement the drag and move we will need to use the following events:

  • MouseDown
  • MouseMove
  • MouseUp
MouseDown event

Continue Reading...
Write Article for Dev102

Write for Dev102!

We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution

Learn More