Custom drag and drop for WP7

I am trying to find a way to display a text block or that will allow me to randomly drag and drop this control around the screen.

I looked at google here too, but every drag-and-drop question that I find is exchanging data, not just the position.

Does anyone know of something ready to go, or can you point me in the direction I should look?

+5
source share
3 answers

You can do this using the behavior:

<TextBlock Text="Hello!">
    <i:Interaction.Behaviors>
        <el:MouseDragElementBehavior ConstrainToParentBounds="True"/>
    </i:Interaction.Behaviors>
</TextBlock>

You need to add a link to Microsoft.Expression.Interactions in your solution and the following namespace at the top of your XAML file:

xmlns:el="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
+4
source

xaml:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <TextBlock Height="30" Margin="125,132,0,0"
               Name="textBlock1" Text="TextBlock"
               Width="83" MouseMove="textBlock1_MouseMove" />
</Grid>

and the code behind:

private void textBlock1_MouseMove(object sender, MouseEventArgs e)
{
   TextBlock realSender = (TextBlock)sender;
   var theParent = (Grid)realSender.Parent;
   var position = e.GetPosition(theParent);
   realSender.Margin = new Thickness(
                       position.X - realSender.Width / 2,
                       position.Y - realSender.Height / 2, 0, 0);

}
+3
source

, .

Not sure if he is still there, although he was based on gesture support, which has since become outdated. If he left, check out August 2011 .

0
source

All Articles