Ich habe eine Anwendung, die sehr "verbindungsbasiert" ist, d. H. Mehrere Eingänge/Ausgänge.Wie kann ich ein hängendes Kabel in WPF simulieren?
Das UI-Konzept eines "Kabels" ist genau das, was ich suche, um das Konzept für den Benutzer klar zu machen. Einen ähnlichen Ansatz verfolgte Propellerhead in der Reason-Software für Audiokomponenten, dargestellt in this YouTube video (fast forward to 2m:50s).
Ich kann dieses Konzept in GDI arbeiten, indem ich einen Spline von Punkt A nach Punkt B male, es gibt eine elegantere Art, Pfade oder etwas in WPF dafür zu verwenden, aber wo fängst du an? Gibt es eine gute Möglichkeit, die Animation des Kabelschwingens zu simulieren, wenn Sie es greifen und schütteln?
Ich bin auch offen für die Kontrolle Bibliotheken (kommerzielle oder Open Source), wenn dieses Rad bereits für WPF erfunden wurde.
Update: Dank der Links in den Antworten bin ich fast da.
Ich habe ein BezierCurve
programmatisch erstellt, mit Punkt 1 ist (0, 0)
, Punkt 2 der Boden „hängen“ Punkt zu sein, und Punkt 3 zu sein, wo sich der Mauscursor ist. Ich habe eine PointAnimation
für Punkt 2 mit einer ElasticEase
Beschleunigungsfunktion erstellt, die angewendet wird, um den "Swinging" -Effekt zu erhalten (d. H. Den Mittelpunkt um ein Bit herum zu springen).
Das einzige Problem ist, die Animation scheint ein wenig zu spät zu laufen. Ich starte das Storyboard jedes Mal, wenn sich die Maus bewegt. Gibt es einen besseren Weg, diese Animation zu machen? Meine Lösung so weit hier befindet:
Code:
private Path _path = null;
private BezierSegment _bs = null;
private PathFigure _pFigure = null;
private Storyboard _sb = null;
private PointAnimation _paPoint2 = null;
ElasticEase _eEase = null;
private void cvCanvas_MouseMove(object sender, MouseEventArgs e)
{
var position = e.GetPosition(cvCanvas);
AdjustPath(position.X, position.Y);
}
// basic idea: when mouse moves, call AdjustPath and draw line from (0,0) to mouse position with a "hang" in the middle
private void AdjustPath(double x, double y)
{
if (_path == null)
{
_path = new Path();
_path.Stroke = new SolidColorBrush(Colors.Blue);
_path.StrokeThickness = 2;
cvCanvas.Children.Add(_path);
_bs = new BezierSegment(new Point(0, 0), new Point(0, 0), new Point(0, 0), true);
PathSegmentCollection psCollection = new PathSegmentCollection();
psCollection.Add(_bs);
_pFigure = new PathFigure();
_pFigure.Segments = psCollection;
_pFigure.StartPoint = new Point(0, 0);
PathFigureCollection pfCollection = new PathFigureCollection();
pfCollection.Add(_pFigure);
PathGeometry pathGeometry = new PathGeometry();
pathGeometry.Figures = pfCollection;
_path.Data = pathGeometry;
}
double bottomOfCurveX = ((x/2));
double bottomOfCurveY = (y + (x * 1.25));
_bs.Point3 = new Point(x, y);
if (_sb == null)
{
_paPoint2 = new PointAnimation();
_paPoint2.From = _bs.Point2;
_paPoint2.To = new Point(bottomOfCurveX, bottomOfCurveY);
_paPoint2.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
_eEase = new ElasticEase();
_paPoint2.EasingFunction = _eEase;
_sb = new Storyboard();
Storyboard.SetTarget(_paPoint2, _path);
Storyboard.SetTargetProperty(_paPoint2, new PropertyPath("Data.Figures[0].Segments[0].Point2"));
_sb.Children.Add(_paPoint2);
_sb.Begin(this);
}
_paPoint2.From = _bs.Point2;
_paPoint2.To = new Point(bottomOfCurveX, bottomOfCurveY);
_sb.Begin(this);
}
Versuchen Sie, eine Kettenlinie zu zeichnen? http://en.wikipedia.org/wiki/Catenary – Gabe
@Gabe, ja, das scheint die Art der Kurve zu sein, die ich suche – Brandon
Haben Sie http://www.tinaja.com/glib/bezcat gesehen. pdf? – Gabe