WPA Animated Progress Bar

05/05/2018 00:27 Lucky_Patcher#1
Hallöchen,

zur zeit versuche ich meine ProgressBar so zu gestallten, dass wenn der Value Wert 100 erreicht hat, dass der Splash Screen sich schließt und das Hauptmodul geladen wird. Aber ich scheitere an folgendem Problem (WPA war nie so wirklich meines)

Code:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Threading;

namespace Cabal_EU_Online_Hack
{
    /// <summary>
    /// Interaktionslogik für Splash.xaml
    /// </summary>
    public partial class Splash : Window
    {
        DispatcherTimer timer = new DispatcherTimer();

        public Splash()
        {
            InitializeComponent();
            createtimer();
        }

        private void createtimer()
        {
            splashProgress.IsIndeterminate = false;

            Duration dur = new Duration(TimeSpan.FromSeconds(10));
            DoubleAnimation dba = new DoubleAnimation(200.0, dur);

            splashProgress.BeginAnimation(ProgressBar.ValueProperty, dba);

            if (splashProgress.Value == 100)
            {
                timer.Stop();
                MainWindow mw = new MainWindow();
                this.Hide();
                mw.Show();
            }
        }
        private void move(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }

        private void splashScreen_Loaded(object sender, RoutedEventArgs e)
        {
            timer.Start();
        }
    }
}
Die Animation erfolgt, aber es passiert nichts, da keine Value increased wird. Was kann ich nun anders machen, um eine Animation zu haben, aber auch einen unsichtbaren Value Wert?
05/05/2018 01:33 ComputerBaer#2
Also dein Problem ist da vor allem ein Denkfehler. Dein Programm wartet nach "BeginAnimation" nicht bis die Adnimation zu Ende ist, sondern läuft sofort weiter. Bei dem Durchlauf ist "Value" natürlich noch 0, danach wird die Methode nie wieder aufgerufen und damit auch der Vergleich nie wieder durchgeführt.

Für eine Lösung habe ich jetzt die Dokumentation gequält, da ich mit den Animationen auch noch nie gearbeitet habe.
Code:
        private void createtimer()
        {
            splashProgress.IsIndeterminate = false;

            Duration dur = new Duration(TimeSpan.FromSeconds(10));
            DoubleAnimation dba = new DoubleAnimation(200.0, dur);
            dba.Completed += () => {
                timer.Stop();
                MainWindow mw = new MainWindow();
                this.Hide();
                mw.Show();
            };

            splashProgress.BeginAnimation(ProgressBar.ValueProperty, dba);
        }
(Eventuell auch mit Tippfehlern, habe den Code hier im Browser geschrieben)
[Only registered and activated users can see links. Click Here To Register...]

Den Timer verwendest du nicht, den kannst du eigentlich auch entfernen.
05/05/2018 01:57 Lucky_Patcher#3
Ich habe das ganze nun mal anders gemacht, mit meinem Timer, und nun funktioniert es perfekt ;)

Code:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Threading;

namespace Cabal_EU_Online_Hack
{
    /// <summary>
    /// Interaktionslogik für Splash.xaml
    /// </summary>
    public partial class Splash : Window
    {
        DispatcherTimer timer = new DispatcherTimer();
        
        public Splash()
        {
            InitializeComponent();

            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = new TimeSpan(0, 0, 1);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            splashProgress.IsIndeterminate = false;

            Duration dur = new Duration(TimeSpan.FromSeconds(10));
            DoubleAnimation dba = new DoubleAnimation(200.0, dur);

            splashProgress.BeginAnimation(ProgressBar.ValueProperty, dba);

            if (splashProgress.Value == 100)
            {
                timer.Stop();
                Login mw = new Login();
                this.Hide();
                mw.Show();
            }
        }

        private void move(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }

        private void splashScreen_Loaded(object sender, RoutedEventArgs e)
        {
            timer.Start();
        }
    }
}
Der Timer füllt den Status und sobald die Animation durch ist, wird in das andere Fenster gesprungen.