annotate Messaging/Common/Controls/MetroTile.cs @ 35:83c1f62d9370

All working except image so far
author adminsh@apollo
date Tue, 27 Mar 2012 16:15:45 +0100
parents
children c8c79f05d76f
rev   line source
35
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
1 using System;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
2 using System.Windows;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
3 using System.Windows.Controls;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
4 using System.Windows.Input;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
5 using System.Windows.Media;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
6 using System.Windows.Media.Imaging;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
7
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
8 namespace Common.Controls
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
9 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
10 [TemplatePart(Name="PART_DISPLAY_ICON", Type=typeof(Image))]
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
11 [TemplatePart(Name = "PART_DISPLAY_COUNT_CONTAINER", Type = typeof(TextBlock))]
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
12 [TemplatePart(Name = "PART_DISPLAY_TITLE_CONTAINER", Type = typeof(TextBlock))]
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
13 public class MetroTile : UserControl
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
14 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
15
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
16 #region Constructor
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
17
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
18 static MetroTile()
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
19 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
20 DefaultStyleKeyProperty.OverrideMetadata(typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
21 new FrameworkPropertyMetadata(typeof(MetroTile)));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
22
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
23 CommandManager.RegisterClassCommandBinding(
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
24 typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
25 new CommandBinding(ResetCountCommand, OnResetCountCommand));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
26 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
27
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
28 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
29
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
30 #region Dependency Properties
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
31
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
32 #region DisplayIcon
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
33
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
34 /// <summary>
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
35 /// Icon for the tile
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
36 /// </summary>
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
37 public static readonly DependencyProperty DisplayIconProperty =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
38 DependencyProperty.Register("DisplayIcon",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
39 typeof(Image),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
40 typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
41 new PropertyMetadata(null));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
42
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
43 public Image DisplayIcon
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
44 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
45 get { return (Image) this.GetValue(DisplayIconProperty); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
46 set { this.SetValue(DisplayIconProperty, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
47 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
48 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
49
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
50 #region DisplayCount
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
51
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
52 /// <summary>
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
53 /// Display count for the tile
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
54 /// </summary>
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
55 public static readonly DependencyProperty DisplayCountProperty =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
56 DependencyProperty.Register("DisplayCount",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
57 typeof(int),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
58 typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
59 new UIPropertyMetadata(0));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
60
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
61 public int DisplayCount
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
62 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
63 get { return (int)this.GetValue(DisplayCountProperty); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
64 set { this.SetValue(DisplayCountProperty, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
65 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
66
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
67 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
68
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
69 #region DisplayText
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
70
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
71 /// <summary>
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
72 /// Main Display text for the tile
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
73 /// </summary>
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
74 public static readonly DependencyProperty DisplayTextProperty =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
75 DependencyProperty.Register("DisplayText",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
76 typeof(string),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
77 typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
78 new PropertyMetadata("Not set"));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
79
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
80 public string DisplayText
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
81 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
82 get { return (string)this.GetValue(DisplayTextProperty); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
83 set { this.SetValue(DisplayTextProperty, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
84 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
85 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
86
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
87 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
88
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
89 #region Events
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
90
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
91 public static readonly RoutedEvent DisplayCountChangedEvent =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
92 EventManager.RegisterRoutedEvent("DisplayCountChanged",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
93 RoutingStrategy.Bubble,
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
94 typeof(RoutedEventHandler),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
95 typeof(MetroTile));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
96
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
97 public event RoutedEventHandler DisplayCountChanged
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
98 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
99 add { AddHandler(DisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
100 remove { RemoveHandler(DisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
101 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
102
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
103 protected virtual void OnDisplayCountChanged(int oldValue, int newValue)
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
104 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
105 // 1. Pair of events: A preview that tunnels and a main event that bubbles
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
106 // 2. We could also create our own RoutedEventArgs that includes oldValue & new Value
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
107
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
108 var previewEvent = new RoutedEventArgs(PreviewDisplayCountChangedEvent);
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
109 RaiseEvent(previewEvent);
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
110
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
111 var e = new RoutedEventArgs(DisplayCountChangedEvent);
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
112 RaiseEvent(e);
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
113 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
114
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
115 public static readonly RoutedEvent PreviewDisplayCountChangedEvent =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
116 EventManager.RegisterRoutedEvent("PreviewDisplayCountChanged",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
117 RoutingStrategy.Tunnel,
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
118 typeof(RoutedEventHandler),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
119 typeof(MetroTile));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
120
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
121 public event RoutedEventHandler PreviewDisplayCountChanged
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
122 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
123 add { AddHandler(PreviewDisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
124 remove { RemoveHandler(PreviewDisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
125 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
126
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
127 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
128
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
129 #region Commands
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
130
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
131 public static readonly ICommand ResetCountCommand =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
132 new RoutedUICommand("ResetCount", "ResetCount", typeof(MetroTile));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
133
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
134 private static void OnResetCountCommand(object sender, ExecutedRoutedEventArgs e)
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
135 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
136 var target = (MetroTile)sender;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
137 target.DisplayCount = 0;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
138 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
139
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
140 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
141
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
142 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
143 }