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