forked from amibar/SmartThreadPool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsageControl.xaml.cs
More file actions
109 lines (90 loc) · 2.54 KB
/
Copy pathUsageControl.xaml.cs
File metadata and controls
109 lines (90 loc) · 2.54 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace STPWPDemo
{
public partial class UsageControl : UserControl
{
private int _rows = 30;
private int _columns = 2;
private int _max = 100; // Maximum value for progress range
private int _value1 = 30; // Current progress
private int _value2 = 60; // Current progress
public int Value1
{
get { return _value1; }
set
{
_value1 = value;
UpdateDisplay();
}
}
public int Value2
{
get { return _value2; }
set
{
_value2 = value;
UpdateDisplay();
}
}
public int Maximum
{
get { return _max; }
set
{
_max = value;
UpdateDisplay();
}
}
public UsageControl()
{
InitializeComponent();
}
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
LayoutRoot.Height = _rows * 4;
LayoutRoot.Width = _columns * 18;
LayoutRoot.RowDefinitions.Clear();
for (int i = 0; i < _rows; i++)
{
LayoutRoot.RowDefinitions.Add(new RowDefinition());
}
UpdateDisplay();
}
private void UpdateDisplay()
{
LayoutRoot.Children.Clear();
for (int j = 0; j < _columns; j++)
{
for (int i = 0; i < _rows; i++)
{
Brush brush = EmptyCell;
int percent = i * _max / _rows;
if (percent < _value2)
{
brush = RedCell;
}
if (percent < _value1)
{
brush = GreenCell;
}
Border border = new Border { Background = brush };
Grid.SetRow(border, _rows - i - 1);
Grid.SetColumn(border, j);
LayoutRoot.Children.Add(border);
}
}
}
}
}