aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.Common/Behaviors/CircularProgressBarBehavior.cs
blob: 24162d17641bd2aab68b829bfbb035fa576706cf (plain)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;

namespace Tango.FSE.Common.Behaviors
{
    public class CircularProgressBarBehavior : StyleBehavior<ProgressBar, CircularProgressBarBehavior>
    {
        public static readonly DependencyProperty StrokeThicknessProperty =
            DependencyProperty.RegisterAttached("StrokeThickness", typeof(double), typeof(CircularProgressBarBehavior), new PropertyMetadata(3d));

        public static double GetStrokeThickness(DependencyObject dependencyObject)
        {
            return (double)dependencyObject.GetValue(StrokeThicknessProperty);
        }

        protected override void OnAttached()
        {
            base.OnAttached();

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            var path = AssociatedObject.FindVisualChildren<Path>().FirstOrDefault(e => e.Name.Equals("Path"));

            if (path != null)
                path.StrokeThickness = GetStrokeThickness(AssociatedObject);
        }

        public static void SetStrokeThickness(DependencyObject dependencyObject, double value)
        {
            dependencyObject.SetValue(StrokeThicknessProperty, value);
        }
    }
}