annotate Messaging/Common/Controls/MetroTile.cs @ 88:e84dc4926a5a

OSL work from 2011
author stevenhollidge <stevenhollidge@hotmail.com>
date Fri, 27 Apr 2012 08:44:37 +0100
parents c8c79f05d76f
children
rev   line source
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
1 using System.ComponentModel;
35
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
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
7 namespace Common.Controls
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
8 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
9 [TemplatePart(Name="PART_DISPLAY_ICON", Type=typeof(Image))]
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
10 [TemplatePart(Name = "PART_DISPLAY_COUNT_CONTAINER", Type = typeof(TextBlock))]
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
11 [TemplatePart(Name = "PART_DISPLAY_TITLE_CONTAINER", Type = typeof(TextBlock))]
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
12 [Description("Represents a metro styled tile that displays an icon, a count and a title")]
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
13 public class MetroTile : Control
35
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 #region Constructor
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
16
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
17 static MetroTile()
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
18 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
19 DefaultStyleKeyProperty.OverrideMetadata(typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
20 new FrameworkPropertyMetadata(typeof(MetroTile)));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
21
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
22 CommandManager.RegisterClassCommandBinding(
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
23 typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
24 new CommandBinding(ResetCountCommand, OnResetCountCommand));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
25 }
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 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
28
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
29 #region Dependency Properties
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
30
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
31 #region DisplayIcon
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
32
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
33 public static readonly DependencyProperty DisplayIconProperty =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
34 DependencyProperty.Register("DisplayIcon",
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
35 typeof (ImageSource),
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
36 typeof (MetroTile),
35
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
37 new PropertyMetadata(null));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
38
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
39 [Description("The icon displayed in the tile."), Category("Common Properties")]
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
40 public ImageSource DisplayIcon
35
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
41 {
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
42 get { return (ImageSource)this.GetValue(DisplayIconProperty); }
35
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
43 set { this.SetValue(DisplayIconProperty, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
44 }
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
45
35
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
46 #endregion
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 #region DisplayCount
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 public static readonly DependencyProperty DisplayCountProperty =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
51 DependencyProperty.Register("DisplayCount",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
52 typeof(int),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
53 typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
54 new UIPropertyMetadata(0));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
55
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
56 [Description("The count displayed in the tile."), Category("Common Properties")]
35
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
57 public int DisplayCount
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
58 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
59 get { return (int)this.GetValue(DisplayCountProperty); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
60 set { this.SetValue(DisplayCountProperty, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
61 }
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 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
64
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
65 #region DisplayText
36
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
66
c8c79f05d76f WORKING VERSION! HIGH FIVE!
adminsh@apollo
parents: 35
diff changeset
67 [Description("The text displayed in the tile."), Category("Common Properties")]
35
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
68 public static readonly DependencyProperty DisplayTextProperty =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
69 DependencyProperty.Register("DisplayText",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
70 typeof(string),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
71 typeof(MetroTile),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
72 new PropertyMetadata("Not set"));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
73
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
74 public string DisplayText
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
75 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
76 get { return (string)this.GetValue(DisplayTextProperty); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
77 set { this.SetValue(DisplayTextProperty, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
78 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
79 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
80
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
81 #endregion
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
82
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
83 #region Events
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 public static readonly RoutedEvent DisplayCountChangedEvent =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
86 EventManager.RegisterRoutedEvent("DisplayCountChanged",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
87 RoutingStrategy.Bubble,
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
88 typeof(RoutedEventHandler),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
89 typeof(MetroTile));
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 event RoutedEventHandler DisplayCountChanged
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
92 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
93 add { AddHandler(DisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
94 remove { RemoveHandler(DisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
95 }
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 protected virtual void OnDisplayCountChanged(int oldValue, int newValue)
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 // 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
100 // 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
101
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
102 var previewEvent = new RoutedEventArgs(PreviewDisplayCountChangedEvent);
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
103 RaiseEvent(previewEvent);
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 var e = new RoutedEventArgs(DisplayCountChangedEvent);
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
106 RaiseEvent(e);
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
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
109 public static readonly RoutedEvent PreviewDisplayCountChangedEvent =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
110 EventManager.RegisterRoutedEvent("PreviewDisplayCountChanged",
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
111 RoutingStrategy.Tunnel,
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
112 typeof(RoutedEventHandler),
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
113 typeof(MetroTile));
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 event RoutedEventHandler PreviewDisplayCountChanged
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
116 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
117 add { AddHandler(PreviewDisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
118 remove { RemoveHandler(PreviewDisplayCountChangedEvent, value); }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
119 }
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 #endregion
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 #region Commands
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
124
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
125 public static readonly ICommand ResetCountCommand =
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
126 new RoutedUICommand("ResetCount", "ResetCount", typeof(MetroTile));
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
127
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
128 private static void OnResetCountCommand(object sender, ExecutedRoutedEventArgs e)
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
129 {
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
130 var target = (MetroTile)sender;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
131 target.DisplayCount = 0;
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
132 }
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 #endregion
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 }
83c1f62d9370 All working except image so far
adminsh@apollo
parents:
diff changeset
137 }