在ScrollViewer(UWP)中移动图像

时间:2015-08-08 17:59:04

标签: c# uwp windows-10 winrt-xaml windows-10-mobile

我在Image ...

中有一个Scrollviewer
<ScrollViewer x:Name="Scrollster" ZoomMode="Enabled" MinZoomFactor="1" MaxZoomFactor="4"
          HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" ManipulationMode="All">
    <Image x:Name="Img" Source="{x:Bind ImgSource}" Stretch="UniformToFill" PointerPressed="Img_PointerPressed"/>
</ScrollViewer>

我想用鼠标指针拖动图像时移动图像!

我试过了:

private void Img_PointerPressed(object sender,PointerRoutedEventArgs e)
{
  var p = e.Pointer;
}

但我无法获得指针位置来更改scrollviewer位置。

我的代码出了什么问题?我做得对吗?

1 个答案:

答案 0 :(得分:7)

应该在<?php //code here to return just the text or whatever // You should actually have the ajax call a page that has the "echoSkill()" // function on it rather than the function page itself echo 'Response to ajax page.'; echoSkill($blah,$blah2,$blah3,$blah4,$blah5,$blah6); print_r($_POST); ?> 控件上设置ManipulationMode。此外,您可能希望指定所需的确切模式,而不是Img以防止不必要的手势处理。

All

从上面的描述中,我认为启用<Image x:Name="Img" Source="{x:Bind ImgSource}" Width="150" Height="150" Stretch="UniformToFill" ManipulationMode="TranslateX, TranslateY" ManipulationStarted="Img_ManipulationStarted" ManipulationDelta="Img_ManipulationDelta" ManipulationCompleted="Img_ManipulationCompleted"> <Image.RenderTransform> <CompositeTransform x:Name="Transform" /> </Image.RenderTransform> </Image> TranslateX就足够了。然后,您需要处理诸如TranslateYManipulationStartedManipulationDelta之类的操纵事件。

你的大多数逻辑都应该在ManipulationCompleted事件中完成,这会在平移过程中多次触发。您可以在此处获得ManipulationDeltaX位置,并相应地进行设置。

以下是一个简单的示例。

Y