aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/App.xaml
blob: ef08a4d98ee6566549009a74794b7d0d245ec92e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
<Application x:Class="Tango.MachineStudio.Stubs.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Tango.MachineStudio.Common;component/Resources/MaterialDesign.xaml" />
                <ResourceDictionary Source="pack://application:,,,/Tango.MachineStudio.Common;component/Themes/LightThemeColors.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
ral.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;

namespace Tango.FirmwareUpdateLib.WPF
{
    /// <summary>
    /// Represents a progress animation component capable of exposing a current and total progress with animations.
    /// </summary>
    /// <seealso cref="System.Windows.FrameworkElement" />
    public class ProgressAnimator : FrameworkElement
    {
        /// <summary>
        /// Gets or sets the animation duration between each update (Default 2 seconds).
        /// </summary>
        public TimeSpan Duration
        {
            get { return (TimeSpan)GetValue(DurationProperty); }
            set { SetValue(DurationProperty, value); }
        }
        public static readonly DependencyProperty DurationProperty =
            DependencyProperty.Register("Duration", typeof(TimeSpan), typeof(ProgressAnimator), new PropertyMetadata(TimeSpan.FromSeconds(1)));

        /// <summary>
        /// Gets or sets the current progress. (Use the ApplyProgress method instead of updating this directly).
        /// </summary>
        public double Current
        {
            get { return (double)GetValue(CurrentProperty); }
            set { SetValue(CurrentProperty, value); }
        }
        public static readonly DependencyProperty CurrentProperty =
            DependencyProperty.Register("Current", typeof(double), typeof(ProgressAnimator), new PropertyMetadata(0.0));

        /// <summary>
        /// Gets or sets the total expected progress.  (Use the ApplyProgress method instead of updating this directly).
        /// </summary>
        public double Total
        {
            get { return (double)GetValue(TotalProperty); }
            set { SetValue(TotalProperty, value); }
        }
        public static readonly DependencyProperty TotalProperty =
            DependencyProperty.Register("Total", typeof(double), typeof(ProgressAnimator), new PropertyMetadata(100.0));

        /// <summary>
        /// Gets or sets a value indicating whether this instance is intermediate.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is intermediate; otherwise, <c>false</c>.
        /// </value>
        public bool IsIntermediate
        {
            get { return (bool)GetValue(IsIntermediateProperty); }
            set { SetValue(IsIntermediateProperty, value); }
        }
        public static readonly DependencyProperty IsIntermediateProperty =
            DependencyProperty.Register("IsIntermediate", typeof(bool), typeof(ProgressAnimator), new PropertyMetadata(true));

        /// <summary>
        /// Applies the progress properties animation.
        /// </summary>
        /// <param name="current">The current.</param>
        /// <param name="total">The total.</param>
        /// <param name="duration">Will override the default duration for the next progress animation.</param>
        public void ApplyProgress(double current, double total, TimeSpan? duration = null)
        {
            Total = total;
            IsIntermediate = false;

            DoubleAnimation ani = new DoubleAnimation();
            ani.To = current;

            ani.Duration = duration != null ? duration.Value : Duration;

            this.BeginAnimation(CurrentProperty, ani, HandoffBehavior.SnapshotAndReplace);
        }

        /// <summary>
        /// Resets the progress properties.
        /// </summary>
        public void ResetProgress()
        {
            this.BeginAnimation(CurrentProperty, null, HandoffBehavior.SnapshotAndReplace);
            Current = 0;
            IsIntermediate = true;
        }
    }
}