简体   繁体   English

如何在不运行Windows运行时保留纵横比的情况下实现压缩变焦?

[英]How implement pinch zoom without preserving aspect ratio in windows runtime?

I have a scrollviewer around a canvas object 我有一个围绕画布对象的scrollviewer

<ScrollViewer>
  <Canvas x:Name="myCanvas"/>
</ScrollViewer>

and I'm adding (lots of) inherited custom controls into the Canvas in the code allowing me to basically create an interactive diagram: 我在代码中向Canvas中添加了(很多)继承的自定义控件,这使我基本上可以创建一个交互式图表:

var myControl = new MyControl();
myControl.Height = 10;
myControl.Width = 20;
Canvas.SetLeft(myControl,5);
Canvas.SetTop(myControl,20);
this.myCanvas.Children.Add(myControl);

The ScrollViewer allows me to pan and pinch zoom around this canvas of controls keeping the same aspect ratio quite nicely. ScrollViewer允许我在这个控件画布周围平移和缩放缩放,保持相同的宽高比。

Is there any way to easily implement stretching using pinching ie zooming without maintaining aspect ratio? 有没有办法轻松实现拉伸使用捏缩即缩放而不保持纵横比?

ScrollViewer doesn't support that. ScrollViewer不支持这一点。 You would need to roll out your own implementation using pointer or manipulation events and RenderTransform. 您需要使用指针或操作事件以及RenderTransform来推出自己的实现。

Something like this (basically implementing Filip's answer): 像这样的东西(基本上实现菲利普的答案):

<Image x:Name="_image" Stretch="None" ManipulationDelta="OnManipulationDelta">
  <Image.RenderTransform>
    <CompositeTransform />
  </Image.RenderTransform>
</Image>

And in the code-behind: 在代码隐藏中:

private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
  var ct = (CompositeTransform)_image.RenderTransform;
  // Scale horizontal.
  ct.ScaleX *= e.Delta.Scale;
  // Scale vertical.
  ct.ScaleY *= e.Delta.Scale;
}

You should only have one of the scaling statements above in your case. 在您的情况下,您应该只有一个缩放语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何实现捏缩放 - How to implement pinch zoom 捏以放大Windows Mobile 6 - pinch to zoom on windows mobile 6 如何调整图像大小而又不影响纵横比 - How to resize the images without disturbing the aspect ratio 如何在不改变宽高比的情况下裁剪图像 - How to Crop Image without changing the aspect ratio 如何缩放具有固定纵横比的多个窗口,以使它们覆盖最大的显示器而不会重叠 - How can I scale multiple windows with fixed aspect ratio so that they cover maximum of monitor without overlapping 如何在运行时调整网格上的WPF控件(保持纵横比) - How to resize WPF controls on a grid at runtime (keeping aspect ratio) 如何在Windows Phone 7中为动态创建的图像添加捏合缩放功能? - how to add pinch zoom functionality to dynamically created image in windows phone 7? 如何基于列/行输入和边距变量以及保留图像的高宽比将最大图像放置在空白位图中 - How to place maximum images in a blank Bitmap based on column/row input & margin variables and preserving aspect ratio of images 如何使用 C# 更改 Windows 媒体播放器的纵横比 - How to change the aspect ratio of an Windows media player by using C# 如何在 Unity 中为 Windows 构建设置纵向纵横比 - How to set portrait aspect ratio for Windows build in Unity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM