开发者

Drag and drop in Windows Phone 7 Mango

开发者 https://www.devze.com 2023-03-23 14:38 出处:网络
How do you implement something like drag and drop using (Silverlight) Windows Phone 7 (Mango)? Ie, I add an image in the center of page,开发者_运维技巧 then want to allow the user to move that image

How do you implement something like drag and drop using (Silverlight) Windows Phone 7 (Mango)?

Ie, I add an image in the center of page,开发者_运维技巧 then want to allow the user to move that image around on screen, possibly also resizing it by pinching.


This turned out to be pretty simple as soon as I started playing around with Expression Blend 4!

This code did it really well for moving around:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
       <Image Margin="129,112,167,122" Source="mypicture.png" Stretch="Fill">
                <Custom:Interaction.Behaviors>
                    <il:MouseDragElementBehavior/>
                </Custom:Interaction.Behaviors>
       </Image>
</Grid>

The key part is that stuff within "Custom:Interaction.Behaviors".

Not sure if this can be used to perform some other custom operations, or do pinching, but I guess it's not too far away?

And this is not only for Mango level Silverlight - I haven't actually installed Mango SDK yet, this should work on earlier versions.

  • I found out that this doesn't seem to allow more than one image dragged at a time. AFAIK, the iPhone supports 11 fingers touching the screen at once - I once built an application where you could move many things around on screen and it worked well at the same time. Not sure what the limits are for WP7 phones but the Samsung I'm using is probably not limited to 1 touch - this is likely a problem with this code. Someone got a better solution?


In Expression Blend 4, Go to Asset tab --> Behavior --> MouseDragElementBehavior to drag the item. To resize by pinching, do you mean double click? you could set onMouseLeftButtonUp and set a counter?

0

精彩评论

暂无评论...
验证码 换一张
取 消