Autor Beitrag
TheTricker
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 16.09.08 16:13 
Hallo liebe Community,

bin ganz neu hier und hoffe auf euere Hilfe.

Ich programmiere einen Prototpyen mit WPF und C#.

Im Moment hänge ich an einer Animation:

Ich lasse im Moment zwei Buttons über den Bildschirm "fliegen" mit Hilfe der Veränderung der Canvas.Top/Left Eigennschaften und einer DoubleAnimation.

Ich habe die Buttons und die Mehtoden statisch, da ich sie von verchiedenen Ort aus anstoßen will.
Jetzt das Problem:

Die Animation wird teilweise nicht angezeigt, dass heißt, der Code wird im Debuger ganz normal durchlaufen, aber man sieht keine Aktion. Außerdem wird die Animation.Completed Aktion ausgeführt, also laufen muss sie.

WEnn ich allerdings einen KeyListener auf das Window lege und in dem EventHandler die Methode Klasse.starteAnimation(); aufrufe, dann funktioniert alles, so wie es soll?

Ich habe überhaupt keine Idee, wieso sie im einen FAll losgeht und angezeigt wird und im anderen Fall anscheinnend losgeht, aber sich nix am Bildschirm tut.

Ich hoffe sehr, dass ihr mir weiterhelfen könnt!

Gruß
TheTricker
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 16.09.08 19:50 
Hallo und :welcome:!

Ich fürchte, ohne Deinen Sourcecode zu kennen, kann man Dir nicht helfen. Wäre also gut, wenn Du den noch nachliefern könntest. Hier gibt's noch eine Hilfeseite dazu, wie man Sourcecode am besten in Beiträgen unterbringt :-)

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
TheTricker Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mi 17.09.08 09:07 
Ja das dachte ich mir schon, abe vielleicht hätte auch so jemand eine Idee gehabt. Hier also mein Code:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
        public static UIElement m_flyElement1 = null;
        public static UIElement m_flyElement2 = null;

...

 public static void animateSwap(string s, string t)
        {
            //m_flyElement1 = s;
            //m_flyElement1 = t

            Console.WriteLine("New Position1" + m_position1.X + ", " + m_position1.Y);
            Console.WriteLine("New Position2" + m_position2.X + ", " + m_position2.Y);

            DoubleAnimation opacityAnimation = new DoubleAnimation();
            opacityAnimation.From = 0.0;
            opacityAnimation.To = 0.7;
            opacityAnimation.AutoReverse = true;
            opacityAnimation.Duration = TimeSpan.Parse("0:0:0.25");
            opacityAnimation.DecelerationRatio = 0.3;
            Duration d = TimeSpan.Parse("0:0:0.5");

            DoubleAnimation doubleAnimation = new DoubleAnimation();
            doubleAnimation.Duration = d;
            doubleAnimation.To = m_position1.X;
            doubleAnimation.From = m_position2.X;

            DoubleAnimation doubleAnimation2 = new DoubleAnimation();
            doubleAnimation2.Duration = d;
            doubleAnimation2.To = m_position1.Y;
            doubleAnimation2.From = m_position2.Y;

            DoubleAnimation doubleAnimation3 = new DoubleAnimation();
            doubleAnimation3.Duration = d;
            doubleAnimation3.To = m_position2.X;
            doubleAnimation3.From = m_position1.X;
            DoubleAnimation doubleAnimation4 = new DoubleAnimation();
            doubleAnimation4.Duration = d;
            doubleAnimation4.To = m_position2.Y;
            doubleAnimation4.From = m_position1.Y;

            doubleAnimation.Completed += afterAnimation;

            if (m_flyElement1 == null || m_flyElement2 == null) { return; }


            m_flyElement1.BeginAnimation(Canvas.TopProperty, doubleAnimation2);
            m_flyElement1.BeginAnimation(Canvas.LeftProperty, doubleAnimation);
            m_flyElement2.BeginAnimation(Canvas.TopProperty, doubleAnimation4);
            m_flyElement2.BeginAnimation(Canvas.LeftProperty, doubleAnimation3);
            m_flyElement1.BeginAnimation(UIElement.OpacityProperty, opacityAnimation);
            m_flyElement2.BeginAnimation(UIElement.OpacityProperty, opacityAnimation);
        }

      private static void afterAnimation(object sender, EventArgs e)
        {
            resetPosition();

        }

        private void keyListener(object sender, KeyEventArgs e)
        {
            ECC.animateSwap("test""bla");
        }


Wenn ich die Zeile ECC.animateSwap("test""bla"); irgendwo im code stehen habe, dann funktioniert sie nicht, bzw, die Animation ist nicht zu sehen. Auf den KeyHandler aber reagiert das ganze und man sieht auch das richtige!
m_position1/2 werden an anderer Stelle gesetzt, funktioniert aber sicher, habe cih mehrfach geprüft. Hoffe jetzt kann man mir helfen .
TheTricker Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mi 17.09.08 12:13 
Also ich habe jetzt nochmal weiter probiert und habe auch neue Ergebnisse:

Wenn ich einen Timer vorschalte, der 0.1 Sekunden wartetn, dann sieht man die Animation?
Sind Animationen gethreaded oder wieso kommt es zu so einem Ergebnis?