Window Animation

  • WPF

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von jedijaeger.

    Window Animation

    Hallo liebe Community,

    ich habe folgenden Code:

    C#-Quellcode

    1. private void AutoAlignPosition(bool animate = false)
    2. {
    3. Size r = SystemParameters.WorkArea.Size;
    4. double targetTop = r.Height - this.Height;
    5. double targetLeft = r.Width - this.Width;
    6. Debug.WriteLine(targetLeft);
    7. Debug.WriteLine(targetTop);
    8. if(!animate)
    9. {
    10. this.Top = targetTop;
    11. this.Left = targetLeft;
    12. }
    13. else
    14. {
    15. DoubleAnimation animatorTop = new DoubleAnimation(this.Top, targetTop, new Duration(TimeSpan.FromSeconds(0.2))) { AutoReverse = false };
    16. DoubleAnimation animatorLeft = new DoubleAnimation(this.Left, targetLeft, new Duration(TimeSpan.FromSeconds(0.2))) { AutoReverse = false };
    17. this.BeginAnimation(Window.LeftProperty, animatorLeft);
    18. this.BeginAnimation(Window.TopProperty, animatorTop);
    19. }
    20. }


    Das Fenster soll über die Taskleiste rechts unten positioniert werden. Passiert auch.

    Jedoch wird die Animation nur einmal ausgeführt. Bei erneutem Ausführen der Methode geschieht nichts mehr. :cursing: (Ja ich habe das Fenster vorher wieder verschoben :whistling: )

    Habe ich vielleicht vergessen irgendeine Property zu ändern? :saint:

    Liebe Grüße
    Julian

    EDIT: Und wäre es möglich hier auch noch eine Trägheit mit einzubauen?
    Hmkay. :|

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „jedijaeger“ ()

    Da hier ja offensichtlich auch niemand Ahnung hat warum bin ich endlich auf die Lösung gekommen :whistling: NACH DREI STUNDEN :thumbsup: ;(

    Also die beiden Animator Objekte scheinen die Top und Left Property irgendwie zu "locken" (im Sinne von Schloss ;) ). Um sie komplett abzubrechen habe ich im Completed Event die entsprechende Property (Top und Left) mit Hilfe der BeginAnimation Methode neu animiert. Allerdings mit null, also kein Animator Objekt beigelegt. Mir ist klar, dass das Probleme gibt, wenn man Compose als HandOffBehaviour hat, aber es funktioniert jetzt so und mehr wollte ich nicht erreichen 8-)

    Hier nochmal der Code:

    C#-Quellcode

    1. private void AutoAlignPosition(bool animate = false)
    2. {
    3. Size r = SystemParameters.WorkArea.Size;
    4. double targetTop = r.Height - this.Height;
    5. double targetLeft = r.Width - this.Width;
    6. if(!animate)
    7. {
    8. this.Top = targetTop;
    9. this.Left = targetLeft;
    10. }
    11. else
    12. {
    13. DoubleAnimation animatorTop = new DoubleAnimation(this.Top, targetTop, new Duration(TimeSpan.FromSeconds(0.2))) { AutoReverse = false };
    14. DoubleAnimation animatorLeft = new DoubleAnimation(this.Left, targetLeft, new Duration(TimeSpan.FromSeconds(0.2))) { AutoReverse = false };
    15. animatorTop.Completed += AnimatorTop_Completed;
    16. animatorLeft.Completed += AnimatorLeft_Completed;
    17. this.BeginAnimation(Window.LeftProperty, animatorLeft);
    18. this.BeginAnimation(Window.TopProperty, animatorTop);
    19. }
    20. }
    21. private void AnimatorLeft_Completed(object sender, EventArgs e)
    22. {
    23. this.BeginAnimation(Window.LeftProperty, null);
    24. }
    25. private void AnimatorTop_Completed(object sender, EventArgs e)
    26. {
    27. this.BeginAnimation(Window.TopProperty, null);
    28. }
    Hmkay. :|
    Das hätte ich dir noch beantwortet, bin aber meistens erst abends online :)
    Das hat übrigens etwas mit dem FillBehavior zu tun (ist auch ne Eigenschaft), die standardmäßig auf HoldEnd ist.


    Zu deiner Frage mit der Trägheit: Ja, das geht, ist sogar ganz einfach: Guck dir mal die EasingFunction an bzw. blogs.msdn.microsoft.com/maxim…h-wpf-4-easing-functions/

    Ich denke mal, du willst den QuadraticEase, welcher das Objekt dann quadratisch beschleunigt. Ich denke mal, dass du das mit der Trägheit meinst :)
    Mfg
    Vincent