WPFExtensions ZoomControl-收缩缩放正在跳跃

WPFExtensions ZoomControl-收缩缩放正在跳跃,wpf,xaml,zooming,behavior,Wpf,Xaml,Zooming,Behavior,我想在WPFExtensions.Controls.ZoomControl中使用夹点手势进行缩放 基于此-我知道如何检测捏手势。我将其用作成员\u检测器。我使用ZoomControl.OperationDelta进行缩放 所以我想我只是用操纵delta像这样缩放: private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e) {

我想在
WPFExtensions.Controls.ZoomControl
中使用夹点手势进行缩放

基于此-我知道如何检测捏手势。我将其用作成员
\u检测器
。我使用
ZoomControl.OperationDelta
进行缩放

所以我想我只是用
操纵delta
像这样缩放:

private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
    if (_detector.IsScalingAllowed) // this just tells me if it is a pinch gesture or not
    {
        if ((e.DeltaManipulation.Scale.X < 1)
            || (e.DeltaManipulation.Scale.X > 1))
        {
            //AssociatedObject is ZoomControl
            AssociatedObject.Zoom = Math.Max(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y);
        }
    }
}
public class ZoomBoxBehaviour : Behavior<ZoomControl>
{
    private GestureDetector _detector;

    protected override void OnAttached()
    {
        base.OnAttached();
        if (AssociatedObject != null)
        {
            _detector = new GestureDetector(AssociatedObject);

            if (!AssociatedObject.IsManipulationEnabled) AssociatedObject.IsManipulationEnabled = true;

            AssociatedObject.ManipulationDelta += AssociatedObject_ManipulationDelta;
        }
    }

    protected override void OnDetaching()
    {
        if (AssociatedObject != null)
        {
            AssociatedObject.ManipulationDelta -= AssociatedObject_ManipulationDelta;
        }

        base.OnDetaching();
    }

    private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
    {
        if (_detector.IsScalingAllowed) // this just tells me if it is a pinch gesture or not
        {
            if ((e.DeltaManipulation.Scale.X < 1)
                || (e.DeltaManipulation.Scale.X > 1))
            {
                AssociatedObject.Zoom = Math.Max(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y);
            }
        }
    }
}
您可以从第一个答案中获取
手势检测器

更新

我让它正确地缩放到中心

    private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
    {
        if (_detector.IsScalingAllowed) // this just tells me if it is a pinch gesture or not
        {
            if ((e.DeltaManipulation.Scale.X < 1)
                || (e.DeltaManipulation.Scale.X > 1))
            {
                AssociatedObject.Zoom = Math.Max(e.CumulativeManipulation.Scale.X, e.CumulativeManipulation.Scale.Y);

                //Size newSize = new Size(AssociatedObject.ZoomBox.Size.Width * e.CumulativeManipulation.Scale.X,
                //                        AssociatedObject.ZoomBox.Size.Height * e.CumulativeManipulation.Scale.Y);

                //AssociatedObject.ZoomTo(new Rect(new Point(0,0), newSize));
            }
        }


    }
private void associated object\u operation delta(对象发送方,System.Windows.Input.operation deltaeventargs e)
{
if(_detector.IsScalingAllowed)//这只是告诉我这是否是一个捏手势
{
if((如DeltaManipulation.Scale.X<1)
||(e.DeltaManipulation.Scale.X>1)
{
AssociatedObject.Zoom=Math.Max(e.CumulativeManipulation.Scale.X,e.CumulativeManipulation.Scale.Y);
//大小newSize=新大小(AssociatedObject.ZoomBox.Size.Width*e.CumulativeManipulation.Scale.X,
//AssociatedObject.ZoomBox.Size.Height*e.CumulativeManipulation.Scale.Y);
//ZoomTo(新Rect(新点(0,0),newSize));
}
}
}
但是现在我想放大到我手势的中心,但是这个注释的
code
只会放大到最大。。。。为什么?我解决了

public class ZoomBoxBehaviour : Behavior<ZoomControl>
    {
        private GestureDetector _detector;
        protected override void OnAttached()
        {
            base.OnAttached();
            if (AssociatedObject != null)
            {
                _detector = new GestureDetector(AssociatedObject);

                if (!AssociatedObject.IsManipulationEnabled) AssociatedObject.IsManipulationEnabled = true;

                AssociatedObject.ManipulationDelta += AssociatedObject_ManipulationDelta;
            }
        }


        protected override void OnDetaching()
        {
            if (AssociatedObject != null)
            {
                AssociatedObject.ManipulationDelta -= AssociatedObject_ManipulationDelta;
            }

            base.OnDetaching();
        }

        private void AssociatedObject_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
        {
            e.ManipulationContainer = ((FrameworkElement)e.Source).Parent as FrameworkElement;
        }

        private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
        {
            if (_detector.IsPanningAllowed)
            {

                // Limit the X/Y translation extent to prevent the element from 'jumping' when using slow touchscreens, or many touch points.
                const double translationThreshold = 100.0;

                //Perform a translation(pan) tranformation
                if ((e.DeltaManipulation.Translation.X < translationThreshold &&
                     e.DeltaManipulation.Translation.X > -translationThreshold)
                )
                {
                    AssociatedObject.TranslateX += e.DeltaManipulation.Translation.X;
                }

                if ((e.DeltaManipulation.Translation.Y < translationThreshold &&
                     e.DeltaManipulation.Translation.Y > -translationThreshold))
                {
                    AssociatedObject.TranslateY += e.DeltaManipulation.Translation.Y;
                }
            }

            if (_detector.IsScalingAllowed) // this just tells me if it is a pinch gesture or not
            {
                if ((e.CumulativeManipulation.Scale.X < 1)
                    || (e.CumulativeManipulation.Scale.X > 1))
                {
                    AssociatedObject.Zoom = Math.Max(e.CumulativeManipulation.Scale.X, e.CumulativeManipulation.Scale.Y);
                }
            }

        }

    }
公共类ZoomBoxBehaviour:行为
{
私人手势检测器_检测器;
受保护的覆盖无效附加()
{
base.onatached();
if(AssociatedObject!=null)
{
_检测器=新的手势检测器(关联对象);
如果(!AssociatedObject.IsManipulationEnabled)AssociatedObject.IsManipulationEnabled=true;
AssociatedObject.OperationDelta+=AssociatedObject\u OperationDelta;
}
}
附加时受保护的覆盖无效()
{
if(AssociatedObject!=null)
{
AssociatedObject.OperationDelta-=AssociatedObject\u OperationDelta;
}
base.OnDetaching();
}
private void Associated object_操纵开始(对象发送方,操纵开始事件参数e)
{
e、 操纵容器=((FrameworkElement)e.Source).Parent作为FrameworkElement;
}
private void Associated object_OperationDelta(对象发送方,System.Windows.Input.OperationDeltaEventArgs e)
{
如果(_检测器ispanning允许)
{
//限制X/Y平移范围,以防止在使用慢速触摸屏或多个触摸点时元素“跳跃”。
常数双平移阈值=100.0;
//执行翻译(pan)转换
if((e.DeltaManipulation.Translation.X-translationThreshold)
)
{
AssociatedObject.TranslateX+=e.DeltaManipulation.Translation.X;
}
if((e.DeltaManipulation.Translation.Y-translationThreshold)
{
AssociatedObject.TranslateY+=e.DeltaManipulation.Translate.Y;
}
}
if(_detector.IsScalingAllowed)//这只是告诉我这是否是一个捏手势
{
if((如累积计算量表X<1)
||(e.累积计算.标度X>1)
{
AssociatedObject.Zoom=Math.Max(e.CumulativeManipulation.Scale.X,e.CumulativeManipulation.Scale.Y);
}
}
}
}