Progressbar Code

using System;

using System.Windows;

using System.Windows.Shapes;

using System.Windows.Controls;

using System.Windows.Media;

using System.Windows.Input;

using System.Reflection;namespace SPFControls

{

public class ProgressBar : Control 
    {

        #region Private Variables

private Rectangle _progressBarTrackRectangle; 
        private Rectangle _progressBarFillRectangle; 
        private string _progressBarLook; 
        private Canvas _progressBarRoot; 
        private double _minValue; 
        private double _maxValue; 
        private double _value;
        #endregion


        #region Public Constructors

        public ProgressBar() 
        { 
            Assembly ProgressBarAssembly = Assembly.GetExecutingAssembly(); 
            System.IO.StreamReader xamlstream = new System.IO.StreamReader((ProgressBarAssembly.GetManifestResourceStream("ProgressBar.ProgressBar.xaml"))); 
            _progressBarLook = xamlstream.ReadToEnd(); 
            _progressBarRoot = InitializeFromXaml(_progressBarLook) as Canvas; 
            _progressBarFillRectangle = _progressBarRoot.FindName("rectProgressBarFill") as Rectangle; 
            _progressBarTrackRectangle = _progressBarRoot.FindName("rectProgressBarTrack") as Rectangle; 
            this.Loaded += new EventHandler(ProgressBar_Loaded); 
        }

void ProgressBar_Loaded(object sender, EventArgs e)
       {
           UpdateLayout();
       }
       #endregion 

#region Public Properties

        public double Minimum 
        { 
            get { return _minValue; } 
            set { _minValue = value; } 
        }

public double Maximum 
        { 
            get { return _maxValue; } 
            set { _maxValue = value; } 
        }

public double Value 
        { 
            get { return _value; } 
            set 
            { 
                if (value <= Maximum && value >= Minimum) 
                { 
                    _value = value; 
                    _progressBarFillRectangle.Width = ((_progressBarTrackRectangle.Width / (_maxValue - _minValue)) * (_value - _minValue)); 
                } 
            } 
        }

public new double Height 
        { 
            get { return ((FrameworkElement)this).Height; } 
            set 
            { 
                ((FrameworkElement)this).Height = value; 
                UpdateLayout(); 
            } 
        }

public new double Width 
        { 
            get { return ((FrameworkElement)this).Width; } 
            set 
            { 
                ((FrameworkElement)this).Width = value; 
                UpdateLayout(); 
            } 
        }

private void UpdateLayout() 
        { 
            _progressBarRoot.Height = Height; 
            _progressBarRoot.Width = Width;

_progressBarFillRectangle.Height = Height; 
            _progressBarFillRectangle.Width = Width;

_progressBarTrackRectangle.Height = Height; 
            _progressBarTrackRectangle.Width = Width; 
        }

#endregion    } 
}

One thought on “Progressbar Code

  1. Pingback: Recursive Reflection : Silverlight ProgressBar Control

Leave a comment