C# ScrollViewer(UWP)中的运动图像

C# ScrollViewer(UWP)中的运动图像,c#,uwp,windows-10,winrt-xaml,windows-10-mobile,C#,Uwp,Windows 10,Winrt Xaml,Windows 10 Mobile,我在Scrollviewer中有一个图像 <ScrollViewer x:Name="Scrollster" ZoomMode="Enabled" MinZoomFactor="1" MaxZoomFactor="4" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" ManipulationMode="All"> <Image x:Name="Img" S

我在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>
但我无法获取指针位置来更改scrollviewer的位置


我的代码怎么了?我做得对吗?

应该在
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>

工作正常,但现在在触摸模式下(桌上和手机),我不能捏放大和缩小!有什么问题吗?我应该在一个新的主题中问它吗?我相信您需要手动打开
操作模式.Scale
并处理
this.Transform.ScaleX
this.Transform.ScaleY
。或者,当有多个联系人时,禁用
操纵模式
,让系统处理放大/缩小操作。现在我知道如何修复它:将系统添加到操纵模式将修复它。我的意思是:
operationmode=“TranslateX,TranslateY,System”
Yes,因为默认模式是System。因此,当我更改为TranslateX n TranslateY时,我禁用了所有系统的自动处理功能:汉克斯。救了我一天!
<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>
void Img_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
    // dim the image while panning
    this.Img.Opacity = 0.4;
}

void Img_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    this.Transform.TranslateX += e.Delta.Translation.X;
    this.Transform.TranslateY += e.Delta.Translation.Y;
}

void Img_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
    // reset the Opacity
    this.Img.Opacity = 1;
}