-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskbarPanel.xaml.cs
108 lines (88 loc) · 3.25 KB
/
TaskbarPanel.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace PMTaskbar
{
/// <summary>
/// Interaction logic for TaskbarPanel.xaml
/// </summary>
public partial class TaskbarPanel : UserControl
{
public TaskbarPanel()
{
InitializeComponent();
StartWallClock();
}
#region depprop
public bool ShowSeconds
{
get { return (bool)GetValue(ShowSecondsProperty); }
set { SetValue(ShowSecondsProperty, value); }
}
// Using a DependencyProperty as the backing store for ShowSeconds. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ShowSecondsProperty =
DependencyProperty.Register("ShowSeconds", typeof(bool), typeof(TaskbarPanel), new PropertyMetadata(false, OnShowSecondsChanged));
static void OnShowSecondsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var c = d as TaskbarPanel;
var val = (bool)e.NewValue;
c.timeFormat = val ? "HH:mm:ss" : "HH:mm";
}
public bool ShowDate
{
get { return (bool)GetValue(ShowDateProperty); }
set { SetValue(ShowDateProperty, value); }
}
// Using a DependencyProperty as the backing store for ShowDate. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ShowDateProperty =
DependencyProperty.Register("ShowDate", typeof(bool), typeof(TaskbarPanel), new PropertyMetadata(false, OnShowDateChanged));
static void OnShowDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var c = d as TaskbarPanel;
var val = (bool)e.NewValue;
c.DateBorder.Visibility = val ? Visibility.Visible : Visibility.Collapsed;
}
#endregion
#region timer
Timer timer;
string timeFormat = "HH:mm";
private void StartWallClock()
{
Tick();
timer = new Timer((o) =>
{
this.Dispatcher.BeginInvoke((Action)(() => Tick()));
timer.Change(1000 - DateTime.Now.Millisecond + 10, 1000);
});
timer.Change(1000 - DateTime.Now.Millisecond + 10, 1000);
}
private void Tick()
{
this.TimeText.Text = DateTime.Now.ToString(timeFormat);
this.WeekdayText.Text = DateTime.Now.ToString("ddd");
if(ShowDate)
this.DateText.Text = DateTime.Now.ToString("dd MMM");
}
#endregion
private void TimeText_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ShowSeconds = !ShowSeconds;
}
private void DateText_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ShowDate = !ShowDate;
}
}
}