J'ai une toile pleine d'objets que je zoom et un panoramique à l'aideWPF transformer la confusion
this.source = VisualTreeHelper.GetChild(this, 0) as FrameworkElement;
this.zoomTransform = new ScaleTransform();
this.transformGroup = new TransformGroup();
this.transformGroup.Children.Add(this.zoomTransform);
this.transformGroup.Children.Add(this.translateTransform);
this.source.RenderTransform = this.transformGroup;
J'ai alors une méthode qui déplace la toile à aa certain point (dans les coordonnées d'origine) au centre de la écran:
public void MoveTo(Point p)
{
var parent= VisualTreeHelper.GetParent(this) as FrameworkElement;
Point centerPoint = new Point(parent.ActualWidth/2, parent.ActualHeight/2);
double x = centerPoint.X - p.X;
double y = centerPoint.Y - p.Y;
x *= this.zoomTransform.ScaleX;
y *= this.zoomTransform.ScaleY;
this.translateTransform.BeginAnimation(TranslateTransform.XProperty, CreatePanAnimation(x), HandoffBehavior.Compose);
this.translateTransform.BeginAnimation(TranslateTransform.YProperty, CreatePanAnimation(y), HandoffBehavior.Compose);
}
private DoubleAnimation CreatePanAnimation(double toValue)
{
var da = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(300)));
da.AccelerationRatio = 0.1;
da.DecelerationRatio = 0.9;
da.FillBehavior = FillBehavior.HoldEnd;
da.Freeze();
return da;
}
Tout fonctionne très bien jusqu'à ce que j'ai réellement une animation de zoom active après laquelle l'animation pan est inexacte. J'ai essayé différentes méthodes de calcul x, y et le point central, mais je n'arrive pas à le faire correctement. Toute aide appréciée, doit être simple :)
Je voudrais aussi faire une méthode à la fois le zoom et casseroles anime à un point, un peu incertain sur la commande pour accomplir cette