Drag and Drop in WP7

I am working on my first ever game… its a simple game. It involves moving bits around the screen 🙂

say you have a bit of Text that you wanted to move around.

<Canvas x:Name="ContentPanel" Grid.Row="1" Margin="191,116,207,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
 <Border BorderThickness="1" Margin="100" BorderBrush="White" ManipulationCompleted="Border_ManipulationCompleted" >
 <i:Interaction.Behaviors>
 <el:MouseDragElementBehavior />
 </i:Interaction.Behaviors>
 <TextBlock Grid.Row="1" TextWrapping="Wrap" Padding="10" Text="A" HorizontalAlignment="Center" />
 </Border>
</Canvas>

this simple change enables you to drag the border control around the canvas.
This MouseDragElementBehaviour exposes two things. A boolean to indicate whether to restrict the drag to the parent and a set of X & Y coordinates that denote the element being dragged.

I am currently working on doing the drop part – actually the drop part is working except the item disappears from the view so once i get that working, i will post some more details here.

A complete example has been posted here
https://invokeit.wordpress.com/2012/02/10/wp7-drag-drop-example/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s