using System;
using System.Windows;
using System.Windows.Threading;
using Microsoft.Phone.Controls;
using System.Windows.Controls;

namespace Controls.Pages
{
    public partial class ProgressBarPage : PhoneApplicationPage
    {
        //private ProgressBar progressBar1;

        public ProgressBarPage()
        {
            InitializeComponent();

            //// normale ProgressBar erstellen im Code Behind
            //progressBar1 = new ProgressBar();
            //progressBar1.Height = 72;
            //progressBar1.Width = 460;
            //progressBar1.Margin = new Thickness(14, 116, 0, 0);
            //progressBar1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            //progressBar1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            //progressBar1.IsIndeterminate = false;
            //progressBar1.Minimum = 0;
            //progressBar1.Maximum = 100;

            //// Indeterminate Progress erstellen im Code Behind
            //ProgressBar progressBar2 = new ProgressBar();
            //progressBar2.Height = 72;
            //progressBar2.Width = 460;
            //progressBar2.Margin = new Thickness(14, 13, 0, 0);
            //progressBar2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            //progressBar2.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            //progressBar2.IsIndeterminate = true;

            //// ProgressBar dem Grid hinzufügen
            //ContentGrid.Children.Add(progressBar1);
            //ContentGrid.Children.Add(progressBar2);
         
        }

        /// <summary>
        /// Ereignismethode nachdem das Layout geladen wurde
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            // Timer erzeugen, der jede Sekunde die Tick Methode ausführt
            DispatcherTimer myDispatcherTimer = new DispatcherTimer();
            myDispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            myDispatcherTimer.Tick += new EventHandler(myDispatcherTimer_Tick);
            myDispatcherTimer.Start();
        }

        /// <summary>
        /// Tick Methode des DispatcherTimer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void myDispatcherTimer_Tick(object sender, EventArgs e)
        {
            // Prüfe, ob Maximun der ProgressBar erreicht wurde
            if (progressBar1.Value <= progressBar1.Maximum)
            { 
                // Fortschrittswert um 1 erhöhen
                progressBar1.Value++;            
            }
        }
    }
}