Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Shapes;
- using System.Windows.Controls.Primitives;
- namespace Progress
- {
- public class ProgressGraph : ContentControl
- {
- private Canvas canvas;
- private Axis axis;
- private Brush brush;
- private Rectangle rectangle;
- private Line line;
- /// <summary>
- /// Initializes a new instance of the <see cref="ProgressGraph"/> class.
- /// </summary>
- public ProgressGraph()
- {
- // Set a default colour for the progress graph
- Color color = Colors.LightGreen;
- color.A = 150;
- this.brush = new SolidColorBrush(color);
- this.axis = new Axis();
- this.canvas = new Canvas();
- this.canvas.ClipToBounds = true;
- this.Content = this.canvas;
- Refresh();
- }
- #region Properties
- #endregion
- /// <inheritdoc />
- protected override void OnRenderSizeChanged(System.Windows.SizeChangedInfo sizeInfo)
- {
- base.OnRenderSizeChanged(sizeInfo);
- this.axis.Height = this.Height;
- this.axis.Width = this.Width;
- this.Refresh();
- }
- private void Refresh()
- {
- try
- {
- this.canvas.Children.Clear();
- this.canvas.Children.Add(this.axis);
- this.rectangle = new Rectangle();
- this.rectangle.Height = this.Height;
- this.rectangle.Width = this.Width;
- this.rectangle.Fill = this.brush;
- this.canvas.Children.Add(this.rectangle);
- this.line = new Line();
- this.line.X1 = 0;
- this.line.X2 = this.Width;
- this.line.Y1 = 10;
- this.line.Y2 = 10;
- this.line.StrokeThickness = 1;
- this.line.SnapsToDevicePixels = true;
- this.line.Stroke = Brushes.Black;
- this.canvas.Children.Add(this.line);
- }
- catch (Exception) { }
- }
- public Double Value
- {
- get
- {
- return this.value;
- }
- set
- {
- #warning Need to stop when we hit 100%
- this.value = value;
- this.rectangle.Dispatcher.Invoke(new Action(() =>
- {
- this.rectangle.Width = (this.Width / 100) * value;
- }));
- }
- }
- private Double value;
- public Double Rate
- {
- get { return this.rate; }
- set
- {
- this.rate = value;
- if (this.rate > this.maxRate)
- this.maxRate = this.rate;
- this.Dispatcher.Invoke(new Action(() =>
- {
- #warning This doesn't correctly max out at 80% which is required to print some text. We'll also need to re-scale the graph :/
- Double rateValue = ((this.Height * 0.8) / this.maxRate) * this.rate;
- this.line.Y1 = rateValue;
- this.line.Y2 = rateValue;
- }));
- }
- }
- private Double rate;
- private Double maxRate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement