[英]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.