问题描述
如何将图像自动移动到我在屏幕上触摸的特定x,y位置?
我尝试使用manipulationStarted,但这不起作用.
这是我的代码:
XML:
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:Name="txttouch" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/> <TextBlock x:Name="txtpoint" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel> <!--ContentPanel - place additional content here--> <Grid x:Name="grid1" Grid.Row="1" Margin="12,0,12,0"> <Image x:Name="imagenew" Source="1.png" Height="30" Width="30"> <Image.RenderTransform> <TranslateTransform x:Name="transimage"/> </Image.RenderTransform> </Image> </Grid> </Grid>
和c#:
private void ManipulationStartedonGrid(object sender,system.Windows.Input.ManipulationStartedEventArgs e) { transimage.X = e.ManipulationOrigin.X; transimage.Y = e.ManipulationOrigin.Y; }
推荐答案
ManipulationOrigin显然是操纵的固定起点.您应该使用ManipulationDelta http://msdn .microsoft.com/en-us/library/system.windows.uielement.manipulationdelta.aspx
其他推荐答案
画布为您提供了明确设置子职位的机会.
<Grid x:Name="grid1" Grid.Row="1" Margin="12,0,12,0"> <Canvas> <Image x:Name="imagenew" Source="1.png" Height="30" Width="30"> <Image.RenderTransform> <TranslateTransform x:Name="transimage"/> </Image.RenderTransform> </Image> </Canvas> </Grid>
在代码集坐标中您需要:
Canvas.SetLeft(imagenew, leftCoord); Canvas.Settop(imagenew, topCoord);
问题描述
How can I move an image automatically to a specific X,Y position where I touch on the screen?
I have tried using ManipulationStarted but this is not working.
This is my code:
XML:
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:Name="txttouch" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/> <TextBlock x:Name="txtpoint" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel> <!--ContentPanel - place additional content here--> <Grid x:Name="grid1" Grid.Row="1" Margin="12,0,12,0"> <Image x:Name="imagenew" Source="1.png" Height="30" Width="30"> <Image.RenderTransform> <TranslateTransform x:Name="transimage"/> </Image.RenderTransform> </Image> </Grid> </Grid>
And C#:
private void ManipulationStartedonGrid(object sender,system.Windows.Input.ManipulationStartedEventArgs e) { transimage.X = e.ManipulationOrigin.X; transimage.Y = e.ManipulationOrigin.Y; }
推荐答案
ManipulationOrigin is obviously the fixed starting point of the manipulation. You should use something like ManipulationDelta http://msdn.microsoft.com/en-us/library/system.windows.uielement.manipulationdelta.aspx
其他推荐答案
Canvas gives you an opportunity to explicitly set child position.
<Grid x:Name="grid1" Grid.Row="1" Margin="12,0,12,0"> <Canvas> <Image x:Name="imagenew" Source="1.png" Height="30" Width="30"> <Image.RenderTransform> <TranslateTransform x:Name="transimage"/> </Image.RenderTransform> </Image> </Canvas> </Grid>
In code set coords you need:
Canvas.SetLeft(imagenew, leftCoord); Canvas.Settop(imagenew, topCoord);