在 Silverlight/WP7 应用程序中使用 MultiTouchBehavior 时,如何以编程方式查找缩放、旋转和平移值?

发布于 2024-10-12 15:43:38 字数 912 浏览 3 评论 0原文

好吧,这似乎是一个非常愚蠢的问题,但我还不太习惯 Silverlight 领域。我正在开发一个引用 Multitouch.Behaviors.WP7 codeplex 项目的 Silverlight / WP7 应用程序 (http://multitouch.codeplex .com/)。

<Canvas x:Name="MyCanvas">
      <Image Source="Images/image.png"
           x:Name="MyImage" Width="120" 
           Canvas.Left="240" Canvas.Top="235">
            <i:Interaction.Behaviors>
                <tb:MultiTouchBehavior
        AreFingersVisible="True" 
        IsDebugModeActive="True" 
        IsMockActive="True" 
        IsRotateEnabled="True" 
        IsScaleEnabled="True" 
        IsTranslateXEnabled="True" 
        IsTranslateYEnabled="True" 
        MaximumScale="100"  
        MinimumScale="0.5"/>
       </i:Interaction.Behaviors>
  </Image>

显然,用户可以使用多点触控功能拖动图像、旋转图像并缩放图像。如何以编程方式访问图像缩放/旋转/平移的值?

Okay, this may seem like a really silly question but I'm not quite used to the Silverlight realm yet. I'm working on a Silverlight / WP7 application that references the Multitouch.Behaviors.WP7 codeplex project (http://multitouch.codeplex.com/).

<Canvas x:Name="MyCanvas">
      <Image Source="Images/image.png"
           x:Name="MyImage" Width="120" 
           Canvas.Left="240" Canvas.Top="235">
            <i:Interaction.Behaviors>
                <tb:MultiTouchBehavior
        AreFingersVisible="True" 
        IsDebugModeActive="True" 
        IsMockActive="True" 
        IsRotateEnabled="True" 
        IsScaleEnabled="True" 
        IsTranslateXEnabled="True" 
        IsTranslateYEnabled="True" 
        MaximumScale="100"  
        MinimumScale="0.5"/>
       </i:Interaction.Behaviors>
  </Image>

Obviously, the user can drag the image around, rotate it, and scale it with the multitouch functionality. How can I access the values for how the image has been scaled/rotated/translated programatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

或十年 2024-10-19 15:43:38

MultitouchBehavior 使用 CompositeTransform 作为 RenderTransform对于与其关联的对象。因此,您可以使用类似于以下的代码来访问转换后的值:

var transform = this.MyImage.RenderTransform as CompositeTransform;
var currentScaleX = transform.ScaleX;
var angle = transform.Rotation;
var offsetX = transform.TranslateX;

The MultitouchBehavior uses a CompositeTransform as the RenderTransform for the object that it is associated with. So, you can use code similar to the following to access the transformed values:

var transform = this.MyImage.RenderTransform as CompositeTransform;
var currentScaleX = transform.ScaleX;
var angle = transform.Rotation;
var offsetX = transform.TranslateX;
莫相离 2024-10-19 15:43:38

您需要使用 Image.RenderTransform。
请参阅这篇文章(特别是 GestureHelper 部分 - http://timheuer.com/blog/archive/2010/09/16/silverlight-toolkit-for-windows-phone-7-released.aspx)。

<Image x:Name="GesturedImage" Source="dividbyzero.jpg" 
       HorizontalAlignment="Center" VerticalAlignment="Center" 
       Width="450" RenderTransformOrigin="0.5,0.5">
    <Image.RenderTransform>
        <ScaleTransform x:Name="ImageScaling" ScaleX="1" ScaleY="1" />
    </Image.RenderTransform>
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener PinchDelta="OnPinchDelta" />
  </toolkit:GestureService.GestureListener>
</Image>

然后使用 DistanceRatio 获取平移值:

private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
   ImageScaling.ScaleX = e.DistanceRatio;
   ImageScaling.ScaleY = e.DistanceRatio;
}

You need to use Image.RenderTransform.
See this post (particularly the GestureHelper section - http://timheuer.com/blog/archive/2010/09/16/silverlight-toolkit-for-windows-phone-7-released.aspx).

<Image x:Name="GesturedImage" Source="dividbyzero.jpg" 
       HorizontalAlignment="Center" VerticalAlignment="Center" 
       Width="450" RenderTransformOrigin="0.5,0.5">
    <Image.RenderTransform>
        <ScaleTransform x:Name="ImageScaling" ScaleX="1" ScaleY="1" />
    </Image.RenderTransform>
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener PinchDelta="OnPinchDelta" />
  </toolkit:GestureService.GestureListener>
</Image>

And then use DistanceRatio to get the value for translation:

private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
   ImageScaling.ScaleX = e.DistanceRatio;
   ImageScaling.ScaleY = e.DistanceRatio;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文