如何将图像自动移动到我触摸屏幕的特定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;
}
答案 0 :(得分:0)
ManipulationOrigin
显然是操纵的固定起点。您应该使用ManipulationDelta
http://msdn.microsoft.com/en-us/library/system.windows.uielement.manipulationdelta.aspx
答案 1 :(得分:0)
Canvas为您提供了明确设置子位置的机会。
<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>
在代码集coords中,您需要:
Canvas.SetLeft(imagenew, leftCoord);
Canvas.Settop(imagenew, topCoord);