root / trunk / NotifyIconWpf / TaskbarIcon.Declarations.cs @ 7fcbf914
History | View | Annotate | Download (74 kB)
1 |
// hardcodet.net NotifyIcon for WPF |
---|---|
2 |
// Copyright (c) 2009 - 2013 Philipp Sumi |
3 |
// Contact and Information: http://www.hardcodet.net |
4 |
// |
5 |
// This library is free software; you can redistribute it and/or |
6 |
// modify it under the terms of the Code Project Open License (CPOL); |
7 |
// either version 1.0 of the License, or (at your option) any later |
8 |
// version. |
9 |
// |
10 |
// The above copyright notice and this permission notice shall be |
11 |
// included in all copies or substantial portions of the Software. |
12 |
// |
13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
14 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
15 |
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
16 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
17 |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
18 |
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
19 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
20 |
// OTHER DEALINGS IN THE SOFTWARE. |
21 |
// |
22 |
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE |
23 |
|
24 |
|
25 |
using System; |
26 |
using System.ComponentModel; |
27 |
using System.Drawing; |
28 |
using System.Windows; |
29 |
using System.Windows.Controls; |
30 |
using System.Windows.Controls.Primitives; |
31 |
using System.Windows.Input; |
32 |
using System.Windows.Media; |
33 |
using Hardcodet.Wpf.TaskbarNotification.Interop; |
34 |
|
35 |
namespace Hardcodet.Wpf.TaskbarNotification |
36 |
{ |
37 |
/// <summary> |
38 |
/// Contains declarations of WPF dependency properties |
39 |
/// and events. |
40 |
/// </summary> |
41 |
partial class TaskbarIcon |
42 |
{ |
43 |
/// <summary> |
44 |
/// Category name that is set on designer properties. |
45 |
/// </summary> |
46 |
public const string CategoryName = "NotifyIcon"; |
47 |
|
48 |
|
49 |
//POPUP CONTROLS |
50 |
|
51 |
#region TrayPopupResolved |
52 |
|
53 |
/// <summary> |
54 |
/// TrayPopupResolved Read-Only Dependency Property |
55 |
/// </summary> |
56 |
private static readonly DependencyPropertyKey TrayPopupResolvedPropertyKey |
57 |
= DependencyProperty.RegisterReadOnly("TrayPopupResolved", typeof (Popup), typeof (TaskbarIcon), |
58 |
new FrameworkPropertyMetadata(null)); |
59 |
|
60 |
|
61 |
/// <summary> |
62 |
/// A read-only dependency property that returns the <see cref="Popup"/> |
63 |
/// that is being displayed in the taskbar area based on a user action. |
64 |
/// </summary> |
65 |
public static readonly DependencyProperty TrayPopupResolvedProperty |
66 |
= TrayPopupResolvedPropertyKey.DependencyProperty; |
67 |
|
68 |
/// <summary> |
69 |
/// Gets the TrayPopupResolved property. Returns |
70 |
/// a <see cref="Popup"/> which is either the |
71 |
/// <see cref="TrayPopup"/> control itself or a |
72 |
/// <see cref="Popup"/> control that contains the |
73 |
/// <see cref="TrayPopup"/>. |
74 |
/// </summary> |
75 |
[Category(CategoryName)] |
76 |
public Popup TrayPopupResolved |
77 |
{ |
78 |
get { return (Popup) GetValue(TrayPopupResolvedProperty); } |
79 |
} |
80 |
|
81 |
/// <summary> |
82 |
/// Provides a secure method for setting the TrayPopupResolved property. |
83 |
/// This dependency property indicates .... |
84 |
/// </summary> |
85 |
/// <param name="value">The new value for the property.</param> |
86 |
protected void SetTrayPopupResolved(Popup value) |
87 |
{ |
88 |
SetValue(TrayPopupResolvedPropertyKey, value); |
89 |
} |
90 |
|
91 |
#endregion |
92 |
|
93 |
#region TrayToolTipResolved |
94 |
|
95 |
/// <summary> |
96 |
/// TrayToolTipResolved Read-Only Dependency Property |
97 |
/// </summary> |
98 |
private static readonly DependencyPropertyKey TrayToolTipResolvedPropertyKey |
99 |
= DependencyProperty.RegisterReadOnly("TrayToolTipResolved", typeof (ToolTip), typeof (TaskbarIcon), |
100 |
new FrameworkPropertyMetadata(null)); |
101 |
|
102 |
|
103 |
/// <summary> |
104 |
/// A read-only dependency property that returns the <see cref="ToolTip"/> |
105 |
/// that is being displayed. |
106 |
/// </summary> |
107 |
public static readonly DependencyProperty TrayToolTipResolvedProperty |
108 |
= TrayToolTipResolvedPropertyKey.DependencyProperty; |
109 |
|
110 |
/// <summary> |
111 |
/// Gets the TrayToolTipResolved property. Returns |
112 |
/// a <see cref="ToolTip"/> control that was created |
113 |
/// in order to display either <see cref="TrayToolTip"/> |
114 |
/// or <see cref="ToolTipText"/>. |
115 |
/// </summary> |
116 |
[Category(CategoryName)] |
117 |
[Browsable(true)] |
118 |
[Bindable(true)] |
119 |
public ToolTip TrayToolTipResolved |
120 |
{ |
121 |
get { return (ToolTip) GetValue(TrayToolTipResolvedProperty); } |
122 |
} |
123 |
|
124 |
/// <summary> |
125 |
/// Provides a secure method for setting the <see cref="TrayToolTipResolved"/> |
126 |
/// property. |
127 |
/// </summary> |
128 |
/// <param name="value">The new value for the property.</param> |
129 |
protected void SetTrayToolTipResolved(ToolTip value) |
130 |
{ |
131 |
SetValue(TrayToolTipResolvedPropertyKey, value); |
132 |
} |
133 |
|
134 |
#endregion |
135 |
|
136 |
#region CustomBalloon |
137 |
|
138 |
/// <summary> |
139 |
/// CustomBalloon Read-Only Dependency Property |
140 |
/// </summary> |
141 |
private static readonly DependencyPropertyKey CustomBalloonPropertyKey |
142 |
= DependencyProperty.RegisterReadOnly("CustomBalloon", typeof (Popup), typeof (TaskbarIcon), |
143 |
new FrameworkPropertyMetadata(null)); |
144 |
|
145 |
/// <summary> |
146 |
/// Maintains a currently displayed custom balloon. |
147 |
/// </summary> |
148 |
public static readonly DependencyProperty CustomBalloonProperty |
149 |
= CustomBalloonPropertyKey.DependencyProperty; |
150 |
|
151 |
/// <summary> |
152 |
/// A custom popup that is being displayed in the tray area in order |
153 |
/// to display messages to the user. |
154 |
/// </summary> |
155 |
public Popup CustomBalloon |
156 |
{ |
157 |
get { return (Popup) GetValue(CustomBalloonProperty); } |
158 |
} |
159 |
|
160 |
/// <summary> |
161 |
/// Provides a secure method for setting the <see cref="CustomBalloon"/> property. |
162 |
/// </summary> |
163 |
/// <param name="value">The new value for the property.</param> |
164 |
protected void SetCustomBalloon(Popup value) |
165 |
{ |
166 |
SetValue(CustomBalloonPropertyKey, value); |
167 |
} |
168 |
|
169 |
#endregion |
170 |
|
171 |
//DEPENDENCY PROPERTIES |
172 |
|
173 |
#region Icon property / IconSource dependency property |
174 |
|
175 |
private Icon icon; |
176 |
|
177 |
/// <summary> |
178 |
/// Gets or sets the icon to be displayed. This is not a |
179 |
/// dependency property - if you want to assign the property |
180 |
/// through XAML, please use the <see cref="IconSource"/> |
181 |
/// dependency property. |
182 |
/// </summary> |
183 |
[Browsable(false)] |
184 |
public Icon Icon |
185 |
{ |
186 |
get { return icon; } |
187 |
set |
188 |
{ |
189 |
icon = value; |
190 |
iconData.IconHandle = value == null ? IntPtr.Zero : icon.Handle; |
191 |
|
192 |
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Icon); |
193 |
} |
194 |
} |
195 |
|
196 |
|
197 |
/// <summary> |
198 |
/// Resolves an image source and updates the <see cref="Icon" /> property accordingly. |
199 |
/// </summary> |
200 |
public static readonly DependencyProperty IconSourceProperty = |
201 |
DependencyProperty.Register("IconSource", |
202 |
typeof (ImageSource), |
203 |
typeof (TaskbarIcon), |
204 |
new FrameworkPropertyMetadata(null, IconSourcePropertyChanged)); |
205 |
|
206 |
/// <summary> |
207 |
/// A property wrapper for the <see cref="IconSourceProperty"/> |
208 |
/// dependency property:<br/> |
209 |
/// Resolves an image source and updates the <see cref="Icon" /> property accordingly. |
210 |
/// </summary> |
211 |
[Category(CategoryName)] |
212 |
[Description("Sets the displayed taskbar icon.")] |
213 |
public ImageSource IconSource |
214 |
{ |
215 |
get { return (ImageSource) GetValue(IconSourceProperty); } |
216 |
set { SetValue(IconSourceProperty, value); } |
217 |
} |
218 |
|
219 |
|
220 |
/// <summary> |
221 |
/// A static callback listener which is being invoked if the |
222 |
/// <see cref="IconSourceProperty"/> dependency property has |
223 |
/// been changed. Invokes the <see cref="OnIconSourcePropertyChanged"/> |
224 |
/// instance method of the changed instance. |
225 |
/// </summary> |
226 |
/// <param name="d">The currently processed owner of the property.</param> |
227 |
/// <param name="e">Provides information about the updated property.</param> |
228 |
private static void IconSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
229 |
{ |
230 |
TaskbarIcon owner = (TaskbarIcon) d; |
231 |
owner.OnIconSourcePropertyChanged(e); |
232 |
} |
233 |
|
234 |
|
235 |
/// <summary> |
236 |
/// Handles changes of the <see cref="IconSourceProperty"/> dependency property. As |
237 |
/// WPF internally uses the dependency property system and bypasses the |
238 |
/// <see cref="IconSource"/> property wrapper, updates of the property's value |
239 |
/// should be handled here. |
240 |
/// </summary> |
241 |
/// <param name="e">Provides information about the updated property.</param> |
242 |
private void OnIconSourcePropertyChanged(DependencyPropertyChangedEventArgs e) |
243 |
{ |
244 |
ImageSource newValue = (ImageSource) e.NewValue; |
245 |
|
246 |
//resolving the ImageSource at design time is unlikely to work |
247 |
if (!Util.IsDesignMode) Icon = newValue.ToIcon(); |
248 |
} |
249 |
|
250 |
#endregion |
251 |
|
252 |
#region ToolTipText dependency property |
253 |
|
254 |
/// <summary> |
255 |
/// A tooltip text that is being displayed if no custom <see cref="ToolTip"/> |
256 |
/// was set or if custom tooltips are not supported. |
257 |
/// </summary> |
258 |
public static readonly DependencyProperty ToolTipTextProperty = |
259 |
DependencyProperty.Register("ToolTipText", |
260 |
typeof (string), |
261 |
typeof (TaskbarIcon), |
262 |
new FrameworkPropertyMetadata(String.Empty, ToolTipTextPropertyChanged)); |
263 |
|
264 |
|
265 |
/// <summary> |
266 |
/// A property wrapper for the <see cref="ToolTipTextProperty"/> |
267 |
/// dependency property:<br/> |
268 |
/// A tooltip text that is being displayed if no custom <see cref="ToolTip"/> |
269 |
/// was set or if custom tooltips are not supported. |
270 |
/// </summary> |
271 |
[Category(CategoryName)] |
272 |
[Description("Alternative to a fully blown ToolTip, which is only displayed on Vista and above.")] |
273 |
public string ToolTipText |
274 |
{ |
275 |
get { return (string) GetValue(ToolTipTextProperty); } |
276 |
set { SetValue(ToolTipTextProperty, value); } |
277 |
} |
278 |
|
279 |
|
280 |
/// <summary> |
281 |
/// A static callback listener which is being invoked if the |
282 |
/// <see cref="ToolTipTextProperty"/> dependency property has |
283 |
/// been changed. Invokes the <see cref="OnToolTipTextPropertyChanged"/> |
284 |
/// instance method of the changed instance. |
285 |
/// </summary> |
286 |
/// <param name="d">The currently processed owner of the property.</param> |
287 |
/// <param name="e">Provides information about the updated property.</param> |
288 |
private static void ToolTipTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
289 |
{ |
290 |
TaskbarIcon owner = (TaskbarIcon) d; |
291 |
owner.OnToolTipTextPropertyChanged(e); |
292 |
} |
293 |
|
294 |
|
295 |
/// <summary> |
296 |
/// Handles changes of the <see cref="ToolTipTextProperty"/> dependency property. As |
297 |
/// WPF internally uses the dependency property system and bypasses the |
298 |
/// <see cref="ToolTipText"/> property wrapper, updates of the property's value |
299 |
/// should be handled here. |
300 |
/// </summary> |
301 |
/// <param name="e">Provides information about the updated property.</param> |
302 |
private void OnToolTipTextPropertyChanged(DependencyPropertyChangedEventArgs e) |
303 |
{ |
304 |
//do not touch tooltips if we have a custom tooltip element |
305 |
if (TrayToolTip == null) |
306 |
{ |
307 |
ToolTip currentToolTip = TrayToolTipResolved; |
308 |
if (currentToolTip == null) |
309 |
{ |
310 |
//if we don't have a wrapper tooltip for the tooltip text, create it now |
311 |
CreateCustomToolTip(); |
312 |
} |
313 |
else |
314 |
{ |
315 |
//if we have a wrapper tooltip that shows the old tooltip text, just update content |
316 |
currentToolTip.Content = e.NewValue; |
317 |
} |
318 |
} |
319 |
|
320 |
WriteToolTipSettings(); |
321 |
} |
322 |
|
323 |
#endregion |
324 |
|
325 |
#region TrayToolTip dependency property |
326 |
|
327 |
/// <summary> |
328 |
/// A custom UI element that is displayed as a tooltip if the user hovers over the taskbar icon. |
329 |
/// Works only with Vista and above. Accordingly, you should make sure that |
330 |
/// the <see cref="ToolTipText"/> property is set as well. |
331 |
/// </summary> |
332 |
public static readonly DependencyProperty TrayToolTipProperty = |
333 |
DependencyProperty.Register("TrayToolTip", |
334 |
typeof (UIElement), |
335 |
typeof (TaskbarIcon), |
336 |
new FrameworkPropertyMetadata(null, TrayToolTipPropertyChanged)); |
337 |
|
338 |
/// <summary> |
339 |
/// A property wrapper for the <see cref="TrayToolTipProperty"/> |
340 |
/// dependency property:<br/> |
341 |
/// A custom UI element that is displayed as a tooltip if the user hovers over the taskbar icon. |
342 |
/// Works only with Vista and above. Accordingly, you should make sure that |
343 |
/// the <see cref="ToolTipText"/> property is set as well. |
344 |
/// </summary> |
345 |
[Category(CategoryName)] |
346 |
[Description("Custom UI element that is displayed as a tooltip. Only on Vista and above")] |
347 |
public UIElement TrayToolTip |
348 |
{ |
349 |
get { return (UIElement) GetValue(TrayToolTipProperty); } |
350 |
set { SetValue(TrayToolTipProperty, value); } |
351 |
} |
352 |
|
353 |
|
354 |
/// <summary> |
355 |
/// A static callback listener which is being invoked if the |
356 |
/// <see cref="TrayToolTipProperty"/> dependency property has |
357 |
/// been changed. Invokes the <see cref="OnTrayToolTipPropertyChanged"/> |
358 |
/// instance method of the changed instance. |
359 |
/// </summary> |
360 |
/// <param name="d">The currently processed owner of the property.</param> |
361 |
/// <param name="e">Provides information about the updated property.</param> |
362 |
private static void TrayToolTipPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
363 |
{ |
364 |
TaskbarIcon owner = (TaskbarIcon) d; |
365 |
owner.OnTrayToolTipPropertyChanged(e); |
366 |
} |
367 |
|
368 |
|
369 |
/// <summary> |
370 |
/// Handles changes of the <see cref="TrayToolTipProperty"/> dependency property. As |
371 |
/// WPF internally uses the dependency property system and bypasses the |
372 |
/// <see cref="TrayToolTip"/> property wrapper, updates of the property's value |
373 |
/// should be handled here. |
374 |
/// </summary> |
375 |
/// <param name="e">Provides information about the updated property.</param> |
376 |
private void OnTrayToolTipPropertyChanged(DependencyPropertyChangedEventArgs e) |
377 |
{ |
378 |
//recreate tooltip control |
379 |
CreateCustomToolTip(); |
380 |
|
381 |
if (e.OldValue != null) |
382 |
{ |
383 |
//remove the taskbar icon reference from the previously used element |
384 |
SetParentTaskbarIcon((DependencyObject) e.OldValue, null); |
385 |
} |
386 |
|
387 |
if (e.NewValue != null) |
388 |
{ |
389 |
//set this taskbar icon as a reference to the new tooltip element |
390 |
SetParentTaskbarIcon((DependencyObject) e.NewValue, this); |
391 |
} |
392 |
|
393 |
//update tooltip settings - needed to make sure a string is set, even |
394 |
//if the ToolTipText property is not set. Otherwise, the event that |
395 |
//triggers tooltip display is never fired. |
396 |
WriteToolTipSettings(); |
397 |
} |
398 |
|
399 |
#endregion |
400 |
|
401 |
#region TrayPopup dependency property |
402 |
|
403 |
/// <summary> |
404 |
/// A control that is displayed as a popup when the taskbar icon is clicked. |
405 |
/// </summary> |
406 |
public static readonly DependencyProperty TrayPopupProperty = |
407 |
DependencyProperty.Register("TrayPopup", |
408 |
typeof (UIElement), |
409 |
typeof (TaskbarIcon), |
410 |
new FrameworkPropertyMetadata(null, TrayPopupPropertyChanged)); |
411 |
|
412 |
/// <summary> |
413 |
/// A property wrapper for the <see cref="TrayPopupProperty"/> |
414 |
/// dependency property:<br/> |
415 |
/// A control that is displayed as a popup when the taskbar icon is clicked. |
416 |
/// </summary> |
417 |
[Category(CategoryName)] |
418 |
[Description("Displayed as a Popup if the user clicks on the taskbar icon.")] |
419 |
public UIElement TrayPopup |
420 |
{ |
421 |
get { return (UIElement) GetValue(TrayPopupProperty); } |
422 |
set { SetValue(TrayPopupProperty, value); } |
423 |
} |
424 |
|
425 |
|
426 |
/// <summary> |
427 |
/// A static callback listener which is being invoked if the |
428 |
/// <see cref="TrayPopupProperty"/> dependency property has |
429 |
/// been changed. Invokes the <see cref="OnTrayPopupPropertyChanged"/> |
430 |
/// instance method of the changed instance. |
431 |
/// </summary> |
432 |
/// <param name="d">The currently processed owner of the property.</param> |
433 |
/// <param name="e">Provides information about the updated property.</param> |
434 |
private static void TrayPopupPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
435 |
{ |
436 |
TaskbarIcon owner = (TaskbarIcon) d; |
437 |
owner.OnTrayPopupPropertyChanged(e); |
438 |
} |
439 |
|
440 |
|
441 |
/// <summary> |
442 |
/// Handles changes of the <see cref="TrayPopupProperty"/> dependency property. As |
443 |
/// WPF internally uses the dependency property system and bypasses the |
444 |
/// <see cref="TrayPopup"/> property wrapper, updates of the property's value |
445 |
/// should be handled here. |
446 |
/// </summary> |
447 |
/// <param name="e">Provides information about the updated property.</param> |
448 |
private void OnTrayPopupPropertyChanged(DependencyPropertyChangedEventArgs e) |
449 |
{ |
450 |
if (e.OldValue != null) |
451 |
{ |
452 |
//remove the taskbar icon reference from the previously used element |
453 |
SetParentTaskbarIcon((DependencyObject) e.OldValue, null); |
454 |
} |
455 |
|
456 |
|
457 |
if (e.NewValue != null) |
458 |
{ |
459 |
//set this taskbar icon as a reference to the new tooltip element |
460 |
SetParentTaskbarIcon((DependencyObject) e.NewValue, this); |
461 |
} |
462 |
|
463 |
//create a pop |
464 |
CreatePopup(); |
465 |
} |
466 |
|
467 |
#endregion |
468 |
|
469 |
#region MenuActivation dependency property |
470 |
|
471 |
/// <summary> |
472 |
/// Defines what mouse events display the context menu. |
473 |
/// Defaults to <see cref="PopupActivationMode.RightClick"/>. |
474 |
/// </summary> |
475 |
public static readonly DependencyProperty MenuActivationProperty = |
476 |
DependencyProperty.Register("MenuActivation", |
477 |
typeof (PopupActivationMode), |
478 |
typeof (TaskbarIcon), |
479 |
new FrameworkPropertyMetadata(PopupActivationMode.RightClick)); |
480 |
|
481 |
/// <summary> |
482 |
/// A property wrapper for the <see cref="MenuActivationProperty"/> |
483 |
/// dependency property:<br/> |
484 |
/// Defines what mouse events display the context menu. |
485 |
/// Defaults to <see cref="PopupActivationMode.RightClick"/>. |
486 |
/// </summary> |
487 |
[Category(CategoryName)] |
488 |
[Description("Defines what mouse events display the context menu.")] |
489 |
public PopupActivationMode MenuActivation |
490 |
{ |
491 |
get { return (PopupActivationMode) GetValue(MenuActivationProperty); } |
492 |
set { SetValue(MenuActivationProperty, value); } |
493 |
} |
494 |
|
495 |
#endregion |
496 |
|
497 |
#region PopupActivation dependency property |
498 |
|
499 |
/// <summary> |
500 |
/// Defines what mouse events trigger the <see cref="TrayPopup" />. |
501 |
/// Default is <see cref="PopupActivationMode.LeftClick" />. |
502 |
/// </summary> |
503 |
public static readonly DependencyProperty PopupActivationProperty = |
504 |
DependencyProperty.Register("PopupActivation", |
505 |
typeof (PopupActivationMode), |
506 |
typeof (TaskbarIcon), |
507 |
new FrameworkPropertyMetadata(PopupActivationMode.LeftClick)); |
508 |
|
509 |
/// <summary> |
510 |
/// A property wrapper for the <see cref="PopupActivationProperty"/> |
511 |
/// dependency property:<br/> |
512 |
/// Defines what mouse events trigger the <see cref="TrayPopup" />. |
513 |
/// Default is <see cref="PopupActivationMode.LeftClick" />. |
514 |
/// </summary> |
515 |
[Category(CategoryName)] |
516 |
[Description("Defines what mouse events display the TaskbarIconPopup.")] |
517 |
public PopupActivationMode PopupActivation |
518 |
{ |
519 |
get { return (PopupActivationMode) GetValue(PopupActivationProperty); } |
520 |
set { SetValue(PopupActivationProperty, value); } |
521 |
} |
522 |
|
523 |
#endregion |
524 |
|
525 |
#region Visibility dependency property override |
526 |
|
527 |
/// <summary> |
528 |
/// A static callback listener which is being invoked if the |
529 |
/// <see cref="UIElement.VisibilityProperty"/> dependency property has |
530 |
/// been changed. Invokes the <see cref="OnVisibilityPropertyChanged"/> |
531 |
/// instance method of the changed instance. |
532 |
/// </summary> |
533 |
/// <param name="d">The currently processed owner of the property.</param> |
534 |
/// <param name="e">Provides information about the updated property.</param> |
535 |
private static void VisibilityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
536 |
{ |
537 |
TaskbarIcon owner = (TaskbarIcon) d; |
538 |
owner.OnVisibilityPropertyChanged(e); |
539 |
} |
540 |
|
541 |
|
542 |
/// <summary> |
543 |
/// Handles changes of the <see cref="UIElement.VisibilityProperty"/> dependency property. As |
544 |
/// WPF internally uses the dependency property system and bypasses the |
545 |
/// <see cref="Visibility"/> property wrapper, updates of the property's value |
546 |
/// should be handled here. |
547 |
/// </summary> |
548 |
/// <param name="e">Provides information about the updated property.</param> |
549 |
private void OnVisibilityPropertyChanged(DependencyPropertyChangedEventArgs e) |
550 |
{ |
551 |
Visibility newValue = (Visibility) e.NewValue; |
552 |
|
553 |
//update |
554 |
if (newValue == Visibility.Visible) |
555 |
{ |
556 |
CreateTaskbarIcon(); |
557 |
} |
558 |
else |
559 |
{ |
560 |
RemoveTaskbarIcon(); |
561 |
} |
562 |
} |
563 |
|
564 |
#endregion |
565 |
|
566 |
#region DataContext dependency property override / target update |
567 |
|
568 |
/// <summary> |
569 |
/// Updates the <see cref="FrameworkElement.DataContextProperty"/> of a given |
570 |
/// <see cref="FrameworkElement"/>. This method only updates target elements |
571 |
/// that do not already have a data context of their own, and either assigns |
572 |
/// the <see cref="FrameworkElement.DataContext"/> of the NotifyIcon, or the |
573 |
/// NotifyIcon itself, if no data context was assigned at all. |
574 |
/// </summary> |
575 |
private void UpdateDataContext(FrameworkElement target, object oldDataContextValue, object newDataContextValue) |
576 |
{ |
577 |
//if there is no target or it's data context is determined through a binding |
578 |
//of its own, keep it |
579 |
if (target == null || target.IsDataContextDataBound()) return; |
580 |
|
581 |
//if the target's data context is the NotifyIcon's old DataContext or the NotifyIcon itself, |
582 |
//update it |
583 |
if (ReferenceEquals(this, target.DataContext) || Equals(oldDataContextValue, target.DataContext)) |
584 |
{ |
585 |
//assign own data context, if available. If there is no data |
586 |
//context at all, assign NotifyIcon itself. |
587 |
target.DataContext = newDataContextValue ?? this; |
588 |
} |
589 |
} |
590 |
|
591 |
/// <summary> |
592 |
/// A static callback listener which is being invoked if the |
593 |
/// <see cref="FrameworkElement.DataContextProperty"/> dependency property has |
594 |
/// been changed. Invokes the <see cref="OnDataContextPropertyChanged"/> |
595 |
/// instance method of the changed instance. |
596 |
/// </summary> |
597 |
/// <param name="d">The currently processed owner of the property.</param> |
598 |
/// <param name="e">Provides information about the updated property.</param> |
599 |
private static void DataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
600 |
{ |
601 |
TaskbarIcon owner = (TaskbarIcon) d; |
602 |
owner.OnDataContextPropertyChanged(e); |
603 |
} |
604 |
|
605 |
|
606 |
/// <summary> |
607 |
/// Handles changes of the <see cref="FrameworkElement.DataContextProperty"/> dependency property. As |
608 |
/// WPF internally uses the dependency property system and bypasses the |
609 |
/// <see cref="FrameworkElement.DataContext"/> property wrapper, updates of the property's value |
610 |
/// should be handled here. |
611 |
/// </summary> |
612 |
/// <param name="e">Provides information about the updated property.</param> |
613 |
private void OnDataContextPropertyChanged(DependencyPropertyChangedEventArgs e) |
614 |
{ |
615 |
object newValue = e.NewValue; |
616 |
object oldValue = e.OldValue; |
617 |
|
618 |
//replace custom data context for ToolTips, Popup, and |
619 |
//ContextMenu |
620 |
UpdateDataContext(TrayPopupResolved, oldValue, newValue); |
621 |
UpdateDataContext(TrayToolTipResolved, oldValue, newValue); |
622 |
UpdateDataContext(ContextMenu, oldValue, newValue); |
623 |
} |
624 |
|
625 |
#endregion |
626 |
|
627 |
#region ContextMenu dependency property override |
628 |
|
629 |
/// <summary> |
630 |
/// A static callback listener which is being invoked if the |
631 |
/// <see cref="FrameworkElement.ContextMenuProperty"/> dependency property has |
632 |
/// been changed. Invokes the <see cref="OnContextMenuPropertyChanged"/> |
633 |
/// instance method of the changed instance. |
634 |
/// </summary> |
635 |
/// <param name="d">The currently processed owner of the property.</param> |
636 |
/// <param name="e">Provides information about the updated property.</param> |
637 |
private static void ContextMenuPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
638 |
{ |
639 |
TaskbarIcon owner = (TaskbarIcon) d; |
640 |
owner.OnContextMenuPropertyChanged(e); |
641 |
} |
642 |
|
643 |
|
644 |
/// <summary> |
645 |
/// Releases the old and updates the new <see cref="ContextMenu"/> property |
646 |
/// in order to reflect both the NotifyIcon's <see cref="FrameworkElement.DataContext"/> |
647 |
/// property and have the <see cref="ParentTaskbarIconProperty"/> assigned. |
648 |
/// </summary> |
649 |
/// <param name="e">Provides information about the updated property.</param> |
650 |
private void OnContextMenuPropertyChanged(DependencyPropertyChangedEventArgs e) |
651 |
{ |
652 |
if (e.OldValue != null) |
653 |
{ |
654 |
//remove the taskbar icon reference from the previously used element |
655 |
SetParentTaskbarIcon((DependencyObject) e.OldValue, null); |
656 |
} |
657 |
|
658 |
if (e.NewValue != null) |
659 |
{ |
660 |
//set this taskbar icon as a reference to the new tooltip element |
661 |
SetParentTaskbarIcon((DependencyObject) e.NewValue, this); |
662 |
} |
663 |
|
664 |
UpdateDataContext((ContextMenu) e.NewValue, null, DataContext); |
665 |
} |
666 |
|
667 |
#endregion |
668 |
|
669 |
#region DoubleClickCommand dependency property |
670 |
|
671 |
/// <summary> |
672 |
/// Associates a command that is being executed if the tray icon is being |
673 |
/// double clicked. |
674 |
/// </summary> |
675 |
public static readonly DependencyProperty DoubleClickCommandProperty = |
676 |
DependencyProperty.Register("DoubleClickCommand", |
677 |
typeof (ICommand), |
678 |
typeof (TaskbarIcon), |
679 |
new FrameworkPropertyMetadata(null)); |
680 |
|
681 |
/// <summary> |
682 |
/// A property wrapper for the <see cref="DoubleClickCommandProperty"/> |
683 |
/// dependency property:<br/> |
684 |
/// Associates a command that is being executed if the tray icon is being |
685 |
/// double clicked. |
686 |
/// </summary> |
687 |
[Category(CategoryName)] |
688 |
[Description("A command that is being executed if the tray icon is being double-clicked.")] |
689 |
public ICommand DoubleClickCommand |
690 |
{ |
691 |
get { return (ICommand) GetValue(DoubleClickCommandProperty); } |
692 |
set { SetValue(DoubleClickCommandProperty, value); } |
693 |
} |
694 |
|
695 |
#endregion |
696 |
|
697 |
#region DoubleClickCommandParameter dependency property |
698 |
|
699 |
/// <summary> |
700 |
/// Command parameter for the <see cref="DoubleClickCommand"/>. |
701 |
/// </summary> |
702 |
public static readonly DependencyProperty DoubleClickCommandParameterProperty = |
703 |
DependencyProperty.Register("DoubleClickCommandParameter", |
704 |
typeof (object), |
705 |
typeof (TaskbarIcon), |
706 |
new FrameworkPropertyMetadata(null)); |
707 |
|
708 |
/// <summary> |
709 |
/// A property wrapper for the <see cref="DoubleClickCommandParameterProperty"/> |
710 |
/// dependency property:<br/> |
711 |
/// Command parameter for the <see cref="DoubleClickCommand"/>. |
712 |
/// </summary> |
713 |
[Category(CategoryName)] |
714 |
[Description("Parameter to submit to the DoubleClickCommand when the user double clicks on the NotifyIcon.")] |
715 |
public object DoubleClickCommandParameter |
716 |
{ |
717 |
get { return GetValue(DoubleClickCommandParameterProperty); } |
718 |
set { SetValue(DoubleClickCommandParameterProperty, value); } |
719 |
} |
720 |
|
721 |
#endregion |
722 |
|
723 |
#region DoubleClickCommandTarget dependency property |
724 |
|
725 |
/// <summary> |
726 |
/// The target of the command that is fired if the notify icon is double clicked. |
727 |
/// </summary> |
728 |
public static readonly DependencyProperty DoubleClickCommandTargetProperty = |
729 |
DependencyProperty.Register("DoubleClickCommandTarget", |
730 |
typeof (IInputElement), |
731 |
typeof (TaskbarIcon), |
732 |
new FrameworkPropertyMetadata(null)); |
733 |
|
734 |
/// <summary> |
735 |
/// A property wrapper for the <see cref="DoubleClickCommandTargetProperty"/> |
736 |
/// dependency property:<br/> |
737 |
/// The target of the command that is fired if the notify icon is double clicked. |
738 |
/// </summary> |
739 |
[Category(CategoryName)] |
740 |
[Description("The target of the command that is fired if the notify icon is double clicked.")] |
741 |
public IInputElement DoubleClickCommandTarget |
742 |
{ |
743 |
get { return (IInputElement) GetValue(DoubleClickCommandTargetProperty); } |
744 |
set { SetValue(DoubleClickCommandTargetProperty, value); } |
745 |
} |
746 |
|
747 |
#endregion |
748 |
|
749 |
#region LeftClickCommand dependency property |
750 |
|
751 |
/// <summary> |
752 |
/// Associates a command that is being executed if the tray icon is being |
753 |
/// double clicked. |
754 |
/// </summary> |
755 |
public static readonly DependencyProperty LeftClickCommandProperty = |
756 |
DependencyProperty.Register("LeftClickCommand", |
757 |
typeof (ICommand), |
758 |
typeof (TaskbarIcon), |
759 |
new FrameworkPropertyMetadata(null)); |
760 |
|
761 |
/// <summary> |
762 |
/// A property wrapper for the <see cref="LeftClickCommandProperty"/> |
763 |
/// dependency property:<br/> |
764 |
/// Associates a command that is being executed if the tray icon is being |
765 |
/// left-clicked. |
766 |
/// </summary> |
767 |
[Category(CategoryName)] |
768 |
[Description("A command that is being executed if the tray icon is being left-clicked.")] |
769 |
public ICommand LeftClickCommand |
770 |
{ |
771 |
get { return (ICommand) GetValue(LeftClickCommandProperty); } |
772 |
set { SetValue(LeftClickCommandProperty, value); } |
773 |
} |
774 |
|
775 |
#endregion |
776 |
|
777 |
#region LeftClickCommandParameter dependency property |
778 |
|
779 |
/// <summary> |
780 |
/// Command parameter for the <see cref="LeftClickCommand"/>. |
781 |
/// </summary> |
782 |
public static readonly DependencyProperty LeftClickCommandParameterProperty = |
783 |
DependencyProperty.Register("LeftClickCommandParameter", |
784 |
typeof (object), |
785 |
typeof (TaskbarIcon), |
786 |
new FrameworkPropertyMetadata(null)); |
787 |
|
788 |
/// <summary> |
789 |
/// A property wrapper for the <see cref="LeftClickCommandParameterProperty"/> |
790 |
/// dependency property:<br/> |
791 |
/// Command parameter for the <see cref="LeftClickCommand"/>. |
792 |
/// </summary> |
793 |
[Category(CategoryName)] |
794 |
[Description("The target of the command that is fired if the notify icon is clicked with the left mouse button." |
795 |
)] |
796 |
public object LeftClickCommandParameter |
797 |
{ |
798 |
get { return GetValue(LeftClickCommandParameterProperty); } |
799 |
set { SetValue(LeftClickCommandParameterProperty, value); } |
800 |
} |
801 |
|
802 |
#endregion |
803 |
|
804 |
#region LeftClickCommandTarget dependency property |
805 |
|
806 |
/// <summary> |
807 |
/// The target of the command that is fired if the notify icon is clicked. |
808 |
/// </summary> |
809 |
public static readonly DependencyProperty LeftClickCommandTargetProperty = |
810 |
DependencyProperty.Register("LeftClickCommandTarget", |
811 |
typeof (IInputElement), |
812 |
typeof (TaskbarIcon), |
813 |
new FrameworkPropertyMetadata(null)); |
814 |
|
815 |
/// <summary> |
816 |
/// A property wrapper for the <see cref="LeftClickCommandTargetProperty"/> |
817 |
/// dependency property:<br/> |
818 |
/// The target of the command that is fired if the notify icon is clicked. |
819 |
/// </summary> |
820 |
[Category(CategoryName)] |
821 |
[Description("The target of the command that is fired if the notify icon is clicked with the left mouse button." |
822 |
)] |
823 |
public IInputElement LeftClickCommandTarget |
824 |
{ |
825 |
get { return (IInputElement) GetValue(LeftClickCommandTargetProperty); } |
826 |
set { SetValue(LeftClickCommandTargetProperty, value); } |
827 |
} |
828 |
|
829 |
#endregion |
830 |
|
831 |
//EVENTS |
832 |
|
833 |
#region TrayLeftMouseDown |
834 |
|
835 |
/// <summary> |
836 |
/// TrayLeftMouseDown Routed Event |
837 |
/// </summary> |
838 |
public static readonly RoutedEvent TrayLeftMouseDownEvent = EventManager.RegisterRoutedEvent( |
839 |
"TrayLeftMouseDown", |
840 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
841 |
|
842 |
/// <summary> |
843 |
/// Occurs when the user presses the left mouse button. |
844 |
/// </summary> |
845 |
[Category(CategoryName)] |
846 |
public event RoutedEventHandler TrayLeftMouseDown |
847 |
{ |
848 |
add { AddHandler(TrayLeftMouseDownEvent, value); } |
849 |
remove { RemoveHandler(TrayLeftMouseDownEvent, value); } |
850 |
} |
851 |
|
852 |
/// <summary> |
853 |
/// A helper method to raise the TrayLeftMouseDown event. |
854 |
/// </summary> |
855 |
protected RoutedEventArgs RaiseTrayLeftMouseDownEvent() |
856 |
{ |
857 |
RoutedEventArgs args = RaiseTrayLeftMouseDownEvent(this); |
858 |
return args; |
859 |
} |
860 |
|
861 |
/// <summary> |
862 |
/// A static helper method to raise the TrayLeftMouseDown event on a target element. |
863 |
/// </summary> |
864 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
865 |
internal static RoutedEventArgs RaiseTrayLeftMouseDownEvent(DependencyObject target) |
866 |
{ |
867 |
if (target == null) return null; |
868 |
|
869 |
RoutedEventArgs args = new RoutedEventArgs(); |
870 |
args.RoutedEvent = TrayLeftMouseDownEvent; |
871 |
RoutedEventHelper.RaiseEvent(target, args); |
872 |
return args; |
873 |
} |
874 |
|
875 |
#endregion |
876 |
|
877 |
#region TrayRightMouseDown |
878 |
|
879 |
/// <summary> |
880 |
/// TrayRightMouseDown Routed Event |
881 |
/// </summary> |
882 |
public static readonly RoutedEvent TrayRightMouseDownEvent = |
883 |
EventManager.RegisterRoutedEvent("TrayRightMouseDown", |
884 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
885 |
|
886 |
/// <summary> |
887 |
/// Occurs when the presses the right mouse button. |
888 |
/// </summary> |
889 |
public event RoutedEventHandler TrayRightMouseDown |
890 |
{ |
891 |
add { AddHandler(TrayRightMouseDownEvent, value); } |
892 |
remove { RemoveHandler(TrayRightMouseDownEvent, value); } |
893 |
} |
894 |
|
895 |
/// <summary> |
896 |
/// A helper method to raise the TrayRightMouseDown event. |
897 |
/// </summary> |
898 |
protected RoutedEventArgs RaiseTrayRightMouseDownEvent() |
899 |
{ |
900 |
return RaiseTrayRightMouseDownEvent(this); |
901 |
} |
902 |
|
903 |
/// <summary> |
904 |
/// A static helper method to raise the TrayRightMouseDown event on a target element. |
905 |
/// </summary> |
906 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
907 |
internal static RoutedEventArgs RaiseTrayRightMouseDownEvent(DependencyObject target) |
908 |
{ |
909 |
if (target == null) return null; |
910 |
|
911 |
RoutedEventArgs args = new RoutedEventArgs(); |
912 |
args.RoutedEvent = TrayRightMouseDownEvent; |
913 |
RoutedEventHelper.RaiseEvent(target, args); |
914 |
return args; |
915 |
} |
916 |
|
917 |
#endregion |
918 |
|
919 |
#region TrayMiddleMouseDown |
920 |
|
921 |
/// <summary> |
922 |
/// TrayMiddleMouseDown Routed Event |
923 |
/// </summary> |
924 |
public static readonly RoutedEvent TrayMiddleMouseDownEvent = |
925 |
EventManager.RegisterRoutedEvent("TrayMiddleMouseDown", |
926 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
927 |
|
928 |
/// <summary> |
929 |
/// Occurs when the user presses the middle mouse button. |
930 |
/// </summary> |
931 |
public event RoutedEventHandler TrayMiddleMouseDown |
932 |
{ |
933 |
add { AddHandler(TrayMiddleMouseDownEvent, value); } |
934 |
remove { RemoveHandler(TrayMiddleMouseDownEvent, value); } |
935 |
} |
936 |
|
937 |
/// <summary> |
938 |
/// A helper method to raise the TrayMiddleMouseDown event. |
939 |
/// </summary> |
940 |
protected RoutedEventArgs RaiseTrayMiddleMouseDownEvent() |
941 |
{ |
942 |
return RaiseTrayMiddleMouseDownEvent(this); |
943 |
} |
944 |
|
945 |
/// <summary> |
946 |
/// A static helper method to raise the TrayMiddleMouseDown event on a target element. |
947 |
/// </summary> |
948 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
949 |
internal static RoutedEventArgs RaiseTrayMiddleMouseDownEvent(DependencyObject target) |
950 |
{ |
951 |
if (target == null) return null; |
952 |
|
953 |
RoutedEventArgs args = new RoutedEventArgs(); |
954 |
args.RoutedEvent = TrayMiddleMouseDownEvent; |
955 |
RoutedEventHelper.RaiseEvent(target, args); |
956 |
return args; |
957 |
} |
958 |
|
959 |
#endregion |
960 |
|
961 |
#region TrayLeftMouseUp |
962 |
|
963 |
/// <summary> |
964 |
/// TrayLeftMouseUp Routed Event |
965 |
/// </summary> |
966 |
public static readonly RoutedEvent TrayLeftMouseUpEvent = EventManager.RegisterRoutedEvent("TrayLeftMouseUp", |
967 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
968 |
|
969 |
/// <summary> |
970 |
/// Occurs when the user releases the left mouse button. |
971 |
/// </summary> |
972 |
public event RoutedEventHandler TrayLeftMouseUp |
973 |
{ |
974 |
add { AddHandler(TrayLeftMouseUpEvent, value); } |
975 |
remove { RemoveHandler(TrayLeftMouseUpEvent, value); } |
976 |
} |
977 |
|
978 |
/// <summary> |
979 |
/// A helper method to raise the TrayLeftMouseUp event. |
980 |
/// </summary> |
981 |
protected RoutedEventArgs RaiseTrayLeftMouseUpEvent() |
982 |
{ |
983 |
return RaiseTrayLeftMouseUpEvent(this); |
984 |
} |
985 |
|
986 |
/// <summary> |
987 |
/// A static helper method to raise the TrayLeftMouseUp event on a target element. |
988 |
/// </summary> |
989 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
990 |
internal static RoutedEventArgs RaiseTrayLeftMouseUpEvent(DependencyObject target) |
991 |
{ |
992 |
if (target == null) return null; |
993 |
|
994 |
RoutedEventArgs args = new RoutedEventArgs(); |
995 |
args.RoutedEvent = TrayLeftMouseUpEvent; |
996 |
RoutedEventHelper.RaiseEvent(target, args); |
997 |
return args; |
998 |
} |
999 |
|
1000 |
#endregion |
1001 |
|
1002 |
#region TrayRightMouseUp |
1003 |
|
1004 |
/// <summary> |
1005 |
/// TrayRightMouseUp Routed Event |
1006 |
/// </summary> |
1007 |
public static readonly RoutedEvent TrayRightMouseUpEvent = EventManager.RegisterRoutedEvent("TrayRightMouseUp", |
1008 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1009 |
|
1010 |
/// <summary> |
1011 |
/// Occurs when the user releases the right mouse button. |
1012 |
/// </summary> |
1013 |
public event RoutedEventHandler TrayRightMouseUp |
1014 |
{ |
1015 |
add { AddHandler(TrayRightMouseUpEvent, value); } |
1016 |
remove { RemoveHandler(TrayRightMouseUpEvent, value); } |
1017 |
} |
1018 |
|
1019 |
/// <summary> |
1020 |
/// A helper method to raise the TrayRightMouseUp event. |
1021 |
/// </summary> |
1022 |
protected RoutedEventArgs RaiseTrayRightMouseUpEvent() |
1023 |
{ |
1024 |
return RaiseTrayRightMouseUpEvent(this); |
1025 |
} |
1026 |
|
1027 |
/// <summary> |
1028 |
/// A static helper method to raise the TrayRightMouseUp event on a target element. |
1029 |
/// </summary> |
1030 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1031 |
internal static RoutedEventArgs RaiseTrayRightMouseUpEvent(DependencyObject target) |
1032 |
{ |
1033 |
if (target == null) return null; |
1034 |
|
1035 |
RoutedEventArgs args = new RoutedEventArgs(); |
1036 |
args.RoutedEvent = TrayRightMouseUpEvent; |
1037 |
RoutedEventHelper.RaiseEvent(target, args); |
1038 |
return args; |
1039 |
} |
1040 |
|
1041 |
#endregion |
1042 |
|
1043 |
#region TrayMiddleMouseUp |
1044 |
|
1045 |
/// <summary> |
1046 |
/// TrayMiddleMouseUp Routed Event |
1047 |
/// </summary> |
1048 |
public static readonly RoutedEvent TrayMiddleMouseUpEvent = EventManager.RegisterRoutedEvent( |
1049 |
"TrayMiddleMouseUp", |
1050 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1051 |
|
1052 |
/// <summary> |
1053 |
/// Occurs when the user releases the middle mouse button. |
1054 |
/// </summary> |
1055 |
public event RoutedEventHandler TrayMiddleMouseUp |
1056 |
{ |
1057 |
add { AddHandler(TrayMiddleMouseUpEvent, value); } |
1058 |
remove { RemoveHandler(TrayMiddleMouseUpEvent, value); } |
1059 |
} |
1060 |
|
1061 |
/// <summary> |
1062 |
/// A helper method to raise the TrayMiddleMouseUp event. |
1063 |
/// </summary> |
1064 |
protected RoutedEventArgs RaiseTrayMiddleMouseUpEvent() |
1065 |
{ |
1066 |
return RaiseTrayMiddleMouseUpEvent(this); |
1067 |
} |
1068 |
|
1069 |
/// <summary> |
1070 |
/// A static helper method to raise the TrayMiddleMouseUp event on a target element. |
1071 |
/// </summary> |
1072 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1073 |
internal static RoutedEventArgs RaiseTrayMiddleMouseUpEvent(DependencyObject target) |
1074 |
{ |
1075 |
if (target == null) return null; |
1076 |
|
1077 |
RoutedEventArgs args = new RoutedEventArgs(); |
1078 |
args.RoutedEvent = TrayMiddleMouseUpEvent; |
1079 |
RoutedEventHelper.RaiseEvent(target, args); |
1080 |
return args; |
1081 |
} |
1082 |
|
1083 |
#endregion |
1084 |
|
1085 |
#region TrayMouseDoubleClick |
1086 |
|
1087 |
/// <summary> |
1088 |
/// TrayMouseDoubleClick Routed Event |
1089 |
/// </summary> |
1090 |
public static readonly RoutedEvent TrayMouseDoubleClickEvent = |
1091 |
EventManager.RegisterRoutedEvent("TrayMouseDoubleClick", |
1092 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1093 |
|
1094 |
/// <summary> |
1095 |
/// Occurs when the user double-clicks the taskbar icon. |
1096 |
/// </summary> |
1097 |
public event RoutedEventHandler TrayMouseDoubleClick |
1098 |
{ |
1099 |
add { AddHandler(TrayMouseDoubleClickEvent, value); } |
1100 |
remove { RemoveHandler(TrayMouseDoubleClickEvent, value); } |
1101 |
} |
1102 |
|
1103 |
/// <summary> |
1104 |
/// A helper method to raise the TrayMouseDoubleClick event. |
1105 |
/// </summary> |
1106 |
protected RoutedEventArgs RaiseTrayMouseDoubleClickEvent() |
1107 |
{ |
1108 |
RoutedEventArgs args = RaiseTrayMouseDoubleClickEvent(this); |
1109 |
DoubleClickCommand.ExecuteIfEnabled(DoubleClickCommandParameter, DoubleClickCommandTarget ?? this); |
1110 |
return args; |
1111 |
} |
1112 |
|
1113 |
/// <summary> |
1114 |
/// A static helper method to raise the TrayMouseDoubleClick event on a target element. |
1115 |
/// </summary> |
1116 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1117 |
internal static RoutedEventArgs RaiseTrayMouseDoubleClickEvent(DependencyObject target) |
1118 |
{ |
1119 |
if (target == null) return null; |
1120 |
|
1121 |
RoutedEventArgs args = new RoutedEventArgs(); |
1122 |
args.RoutedEvent = TrayMouseDoubleClickEvent; |
1123 |
RoutedEventHelper.RaiseEvent(target, args); |
1124 |
return args; |
1125 |
} |
1126 |
|
1127 |
#endregion |
1128 |
|
1129 |
#region TrayMouseMove |
1130 |
|
1131 |
/// <summary> |
1132 |
/// TrayMouseMove Routed Event |
1133 |
/// </summary> |
1134 |
public static readonly RoutedEvent TrayMouseMoveEvent = EventManager.RegisterRoutedEvent("TrayMouseMove", |
1135 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1136 |
|
1137 |
/// <summary> |
1138 |
/// Occurs when the user moves the mouse over the taskbar icon. |
1139 |
/// </summary> |
1140 |
public event RoutedEventHandler TrayMouseMove |
1141 |
{ |
1142 |
add { AddHandler(TrayMouseMoveEvent, value); } |
1143 |
remove { RemoveHandler(TrayMouseMoveEvent, value); } |
1144 |
} |
1145 |
|
1146 |
/// <summary> |
1147 |
/// A helper method to raise the TrayMouseMove event. |
1148 |
/// </summary> |
1149 |
protected RoutedEventArgs RaiseTrayMouseMoveEvent() |
1150 |
{ |
1151 |
return RaiseTrayMouseMoveEvent(this); |
1152 |
} |
1153 |
|
1154 |
/// <summary> |
1155 |
/// A static helper method to raise the TrayMouseMove event on a target element. |
1156 |
/// </summary> |
1157 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1158 |
internal static RoutedEventArgs RaiseTrayMouseMoveEvent(DependencyObject target) |
1159 |
{ |
1160 |
if (target == null) return null; |
1161 |
|
1162 |
var args = new RoutedEventArgs(); |
1163 |
args.RoutedEvent = TrayMouseMoveEvent; |
1164 |
RoutedEventHelper.RaiseEvent(target, args); |
1165 |
return args; |
1166 |
} |
1167 |
|
1168 |
#endregion |
1169 |
|
1170 |
#region TrayBalloonTipShown |
1171 |
|
1172 |
/// <summary> |
1173 |
/// TrayBalloonTipShown Routed Event |
1174 |
/// </summary> |
1175 |
public static readonly RoutedEvent TrayBalloonTipShownEvent = |
1176 |
EventManager.RegisterRoutedEvent("TrayBalloonTipShown", |
1177 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1178 |
|
1179 |
/// <summary> |
1180 |
/// Occurs when a balloon ToolTip is displayed. |
1181 |
/// </summary> |
1182 |
public event RoutedEventHandler TrayBalloonTipShown |
1183 |
{ |
1184 |
add { AddHandler(TrayBalloonTipShownEvent, value); } |
1185 |
remove { RemoveHandler(TrayBalloonTipShownEvent, value); } |
1186 |
} |
1187 |
|
1188 |
/// <summary> |
1189 |
/// A helper method to raise the TrayBalloonTipShown event. |
1190 |
/// </summary> |
1191 |
protected RoutedEventArgs RaiseTrayBalloonTipShownEvent() |
1192 |
{ |
1193 |
return RaiseTrayBalloonTipShownEvent(this); |
1194 |
} |
1195 |
|
1196 |
/// <summary> |
1197 |
/// A static helper method to raise the TrayBalloonTipShown event on a target element. |
1198 |
/// </summary> |
1199 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1200 |
internal static RoutedEventArgs RaiseTrayBalloonTipShownEvent(DependencyObject target) |
1201 |
{ |
1202 |
if (target == null) return null; |
1203 |
|
1204 |
RoutedEventArgs args = new RoutedEventArgs(); |
1205 |
args.RoutedEvent = TrayBalloonTipShownEvent; |
1206 |
RoutedEventHelper.RaiseEvent(target, args); |
1207 |
return args; |
1208 |
} |
1209 |
|
1210 |
#endregion |
1211 |
|
1212 |
#region TrayBalloonTipClosed |
1213 |
|
1214 |
/// <summary> |
1215 |
/// TrayBalloonTipClosed Routed Event |
1216 |
/// </summary> |
1217 |
public static readonly RoutedEvent TrayBalloonTipClosedEvent = |
1218 |
EventManager.RegisterRoutedEvent("TrayBalloonTipClosed", |
1219 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1220 |
|
1221 |
/// <summary> |
1222 |
/// Occurs when a balloon ToolTip was closed. |
1223 |
/// </summary> |
1224 |
public event RoutedEventHandler TrayBalloonTipClosed |
1225 |
{ |
1226 |
add { AddHandler(TrayBalloonTipClosedEvent, value); } |
1227 |
remove { RemoveHandler(TrayBalloonTipClosedEvent, value); } |
1228 |
} |
1229 |
|
1230 |
/// <summary> |
1231 |
/// A helper method to raise the TrayBalloonTipClosed event. |
1232 |
/// </summary> |
1233 |
protected RoutedEventArgs RaiseTrayBalloonTipClosedEvent() |
1234 |
{ |
1235 |
return RaiseTrayBalloonTipClosedEvent(this); |
1236 |
} |
1237 |
|
1238 |
/// <summary> |
1239 |
/// A static helper method to raise the TrayBalloonTipClosed event on a target element. |
1240 |
/// </summary> |
1241 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1242 |
internal static RoutedEventArgs RaiseTrayBalloonTipClosedEvent(DependencyObject target) |
1243 |
{ |
1244 |
if (target == null) return null; |
1245 |
|
1246 |
RoutedEventArgs args = new RoutedEventArgs(); |
1247 |
args.RoutedEvent = TrayBalloonTipClosedEvent; |
1248 |
RoutedEventHelper.RaiseEvent(target, args); |
1249 |
return args; |
1250 |
} |
1251 |
|
1252 |
#endregion |
1253 |
|
1254 |
#region TrayBalloonTipClicked |
1255 |
|
1256 |
/// <summary> |
1257 |
/// TrayBalloonTipClicked Routed Event |
1258 |
/// </summary> |
1259 |
public static readonly RoutedEvent TrayBalloonTipClickedEvent = |
1260 |
EventManager.RegisterRoutedEvent("TrayBalloonTipClicked", |
1261 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1262 |
|
1263 |
/// <summary> |
1264 |
/// Occurs when the user clicks on a balloon ToolTip. |
1265 |
/// </summary> |
1266 |
public event RoutedEventHandler TrayBalloonTipClicked |
1267 |
{ |
1268 |
add { AddHandler(TrayBalloonTipClickedEvent, value); } |
1269 |
remove { RemoveHandler(TrayBalloonTipClickedEvent, value); } |
1270 |
} |
1271 |
|
1272 |
/// <summary> |
1273 |
/// A helper method to raise the TrayBalloonTipClicked event. |
1274 |
/// </summary> |
1275 |
protected RoutedEventArgs RaiseTrayBalloonTipClickedEvent() |
1276 |
{ |
1277 |
return RaiseTrayBalloonTipClickedEvent(this); |
1278 |
} |
1279 |
|
1280 |
/// <summary> |
1281 |
/// A static helper method to raise the TrayBalloonTipClicked event on a target element. |
1282 |
/// </summary> |
1283 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1284 |
internal static RoutedEventArgs RaiseTrayBalloonTipClickedEvent(DependencyObject target) |
1285 |
{ |
1286 |
if (target == null) return null; |
1287 |
|
1288 |
RoutedEventArgs args = new RoutedEventArgs(); |
1289 |
args.RoutedEvent = TrayBalloonTipClickedEvent; |
1290 |
RoutedEventHelper.RaiseEvent(target, args); |
1291 |
return args; |
1292 |
} |
1293 |
|
1294 |
#endregion |
1295 |
|
1296 |
#region TrayContextMenuOpen (and PreviewTrayContextMenuOpen) |
1297 |
|
1298 |
/// <summary> |
1299 |
/// TrayContextMenuOpen Routed Event |
1300 |
/// </summary> |
1301 |
public static readonly RoutedEvent TrayContextMenuOpenEvent = |
1302 |
EventManager.RegisterRoutedEvent("TrayContextMenuOpen", |
1303 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1304 |
|
1305 |
/// <summary> |
1306 |
/// Bubbled event that occurs when the context menu of the taskbar icon is being displayed. |
1307 |
/// </summary> |
1308 |
public event RoutedEventHandler TrayContextMenuOpen |
1309 |
{ |
1310 |
add { AddHandler(TrayContextMenuOpenEvent, value); } |
1311 |
remove { RemoveHandler(TrayContextMenuOpenEvent, value); } |
1312 |
} |
1313 |
|
1314 |
/// <summary> |
1315 |
/// A helper method to raise the TrayContextMenuOpen event. |
1316 |
/// </summary> |
1317 |
protected RoutedEventArgs RaiseTrayContextMenuOpenEvent() |
1318 |
{ |
1319 |
return RaiseTrayContextMenuOpenEvent(this); |
1320 |
} |
1321 |
|
1322 |
/// <summary> |
1323 |
/// A static helper method to raise the TrayContextMenuOpen event on a target element. |
1324 |
/// </summary> |
1325 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1326 |
internal static RoutedEventArgs RaiseTrayContextMenuOpenEvent(DependencyObject target) |
1327 |
{ |
1328 |
if (target == null) return null; |
1329 |
|
1330 |
RoutedEventArgs args = new RoutedEventArgs(); |
1331 |
args.RoutedEvent = TrayContextMenuOpenEvent; |
1332 |
RoutedEventHelper.RaiseEvent(target, args); |
1333 |
return args; |
1334 |
} |
1335 |
|
1336 |
/// <summary> |
1337 |
/// PreviewTrayContextMenuOpen Routed Event |
1338 |
/// </summary> |
1339 |
public static readonly RoutedEvent PreviewTrayContextMenuOpenEvent = |
1340 |
EventManager.RegisterRoutedEvent("PreviewTrayContextMenuOpen", |
1341 |
RoutingStrategy.Tunnel, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1342 |
|
1343 |
/// <summary> |
1344 |
/// Tunneled event that occurs when the context menu of the taskbar icon is being displayed. |
1345 |
/// </summary> |
1346 |
public event RoutedEventHandler PreviewTrayContextMenuOpen |
1347 |
{ |
1348 |
add { AddHandler(PreviewTrayContextMenuOpenEvent, value); } |
1349 |
remove { RemoveHandler(PreviewTrayContextMenuOpenEvent, value); } |
1350 |
} |
1351 |
|
1352 |
/// <summary> |
1353 |
/// A helper method to raise the PreviewTrayContextMenuOpen event. |
1354 |
/// </summary> |
1355 |
protected RoutedEventArgs RaisePreviewTrayContextMenuOpenEvent() |
1356 |
{ |
1357 |
return RaisePreviewTrayContextMenuOpenEvent(this); |
1358 |
} |
1359 |
|
1360 |
/// <summary> |
1361 |
/// A static helper method to raise the PreviewTrayContextMenuOpen event on a target element. |
1362 |
/// </summary> |
1363 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1364 |
internal static RoutedEventArgs RaisePreviewTrayContextMenuOpenEvent(DependencyObject target) |
1365 |
{ |
1366 |
if (target == null) return null; |
1367 |
|
1368 |
RoutedEventArgs args = new RoutedEventArgs(); |
1369 |
args.RoutedEvent = PreviewTrayContextMenuOpenEvent; |
1370 |
RoutedEventHelper.RaiseEvent(target, args); |
1371 |
return args; |
1372 |
} |
1373 |
|
1374 |
#endregion |
1375 |
|
1376 |
#region TrayPopupOpen (and PreviewTrayPopupOpen) |
1377 |
|
1378 |
/// <summary> |
1379 |
/// TrayPopupOpen Routed Event |
1380 |
/// </summary> |
1381 |
public static readonly RoutedEvent TrayPopupOpenEvent = EventManager.RegisterRoutedEvent("TrayPopupOpen", |
1382 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1383 |
|
1384 |
/// <summary> |
1385 |
/// Bubbled event that occurs when the custom popup is being opened. |
1386 |
/// </summary> |
1387 |
public event RoutedEventHandler TrayPopupOpen |
1388 |
{ |
1389 |
add { AddHandler(TrayPopupOpenEvent, value); } |
1390 |
remove { RemoveHandler(TrayPopupOpenEvent, value); } |
1391 |
} |
1392 |
|
1393 |
/// <summary> |
1394 |
/// A helper method to raise the TrayPopupOpen event. |
1395 |
/// </summary> |
1396 |
protected RoutedEventArgs RaiseTrayPopupOpenEvent() |
1397 |
{ |
1398 |
return RaiseTrayPopupOpenEvent(this); |
1399 |
} |
1400 |
|
1401 |
/// <summary> |
1402 |
/// A static helper method to raise the TrayPopupOpen event on a target element. |
1403 |
/// </summary> |
1404 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1405 |
internal static RoutedEventArgs RaiseTrayPopupOpenEvent(DependencyObject target) |
1406 |
{ |
1407 |
if (target == null) return null; |
1408 |
|
1409 |
RoutedEventArgs args = new RoutedEventArgs(); |
1410 |
args.RoutedEvent = TrayPopupOpenEvent; |
1411 |
RoutedEventHelper.RaiseEvent(target, args); |
1412 |
return args; |
1413 |
} |
1414 |
|
1415 |
/// <summary> |
1416 |
/// PreviewTrayPopupOpen Routed Event |
1417 |
/// </summary> |
1418 |
public static readonly RoutedEvent PreviewTrayPopupOpenEvent = |
1419 |
EventManager.RegisterRoutedEvent("PreviewTrayPopupOpen", |
1420 |
RoutingStrategy.Tunnel, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1421 |
|
1422 |
/// <summary> |
1423 |
/// Tunneled event that occurs when the custom popup is being opened. |
1424 |
/// </summary> |
1425 |
public event RoutedEventHandler PreviewTrayPopupOpen |
1426 |
{ |
1427 |
add { AddHandler(PreviewTrayPopupOpenEvent, value); } |
1428 |
remove { RemoveHandler(PreviewTrayPopupOpenEvent, value); } |
1429 |
} |
1430 |
|
1431 |
/// <summary> |
1432 |
/// A helper method to raise the PreviewTrayPopupOpen event. |
1433 |
/// </summary> |
1434 |
protected RoutedEventArgs RaisePreviewTrayPopupOpenEvent() |
1435 |
{ |
1436 |
return RaisePreviewTrayPopupOpenEvent(this); |
1437 |
} |
1438 |
|
1439 |
/// <summary> |
1440 |
/// A static helper method to raise the PreviewTrayPopupOpen event on a target element. |
1441 |
/// </summary> |
1442 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1443 |
internal static RoutedEventArgs RaisePreviewTrayPopupOpenEvent(DependencyObject target) |
1444 |
{ |
1445 |
if (target == null) return null; |
1446 |
|
1447 |
RoutedEventArgs args = new RoutedEventArgs(); |
1448 |
args.RoutedEvent = PreviewTrayPopupOpenEvent; |
1449 |
RoutedEventHelper.RaiseEvent(target, args); |
1450 |
return args; |
1451 |
} |
1452 |
|
1453 |
#endregion |
1454 |
|
1455 |
#region TrayToolTipOpen (and PreviewTrayToolTipOpen) |
1456 |
|
1457 |
/// <summary> |
1458 |
/// TrayToolTipOpen Routed Event |
1459 |
/// </summary> |
1460 |
public static readonly RoutedEvent TrayToolTipOpenEvent = EventManager.RegisterRoutedEvent("TrayToolTipOpen", |
1461 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1462 |
|
1463 |
/// <summary> |
1464 |
/// Bubbled event that occurs when the custom ToolTip is being displayed. |
1465 |
/// </summary> |
1466 |
public event RoutedEventHandler TrayToolTipOpen |
1467 |
{ |
1468 |
add { AddHandler(TrayToolTipOpenEvent, value); } |
1469 |
remove { RemoveHandler(TrayToolTipOpenEvent, value); } |
1470 |
} |
1471 |
|
1472 |
/// <summary> |
1473 |
/// A helper method to raise the TrayToolTipOpen event. |
1474 |
/// </summary> |
1475 |
protected RoutedEventArgs RaiseTrayToolTipOpenEvent() |
1476 |
{ |
1477 |
return RaiseTrayToolTipOpenEvent(this); |
1478 |
} |
1479 |
|
1480 |
/// <summary> |
1481 |
/// A static helper method to raise the TrayToolTipOpen event on a target element. |
1482 |
/// </summary> |
1483 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1484 |
internal static RoutedEventArgs RaiseTrayToolTipOpenEvent(DependencyObject target) |
1485 |
{ |
1486 |
if (target == null) return null; |
1487 |
|
1488 |
RoutedEventArgs args = new RoutedEventArgs(); |
1489 |
args.RoutedEvent = TrayToolTipOpenEvent; |
1490 |
RoutedEventHelper.RaiseEvent(target, args); |
1491 |
return args; |
1492 |
} |
1493 |
|
1494 |
/// <summary> |
1495 |
/// PreviewTrayToolTipOpen Routed Event |
1496 |
/// </summary> |
1497 |
public static readonly RoutedEvent PreviewTrayToolTipOpenEvent = |
1498 |
EventManager.RegisterRoutedEvent("PreviewTrayToolTipOpen", |
1499 |
RoutingStrategy.Tunnel, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1500 |
|
1501 |
/// <summary> |
1502 |
/// Tunneled event that occurs when the custom ToolTip is being displayed. |
1503 |
/// </summary> |
1504 |
public event RoutedEventHandler PreviewTrayToolTipOpen |
1505 |
{ |
1506 |
add { AddHandler(PreviewTrayToolTipOpenEvent, value); } |
1507 |
remove { RemoveHandler(PreviewTrayToolTipOpenEvent, value); } |
1508 |
} |
1509 |
|
1510 |
/// <summary> |
1511 |
/// A helper method to raise the PreviewTrayToolTipOpen event. |
1512 |
/// </summary> |
1513 |
protected RoutedEventArgs RaisePreviewTrayToolTipOpenEvent() |
1514 |
{ |
1515 |
return RaisePreviewTrayToolTipOpenEvent(this); |
1516 |
} |
1517 |
|
1518 |
/// <summary> |
1519 |
/// A static helper method to raise the PreviewTrayToolTipOpen event on a target element. |
1520 |
/// </summary> |
1521 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1522 |
internal static RoutedEventArgs RaisePreviewTrayToolTipOpenEvent(DependencyObject target) |
1523 |
{ |
1524 |
if (target == null) return null; |
1525 |
|
1526 |
RoutedEventArgs args = new RoutedEventArgs(); |
1527 |
args.RoutedEvent = PreviewTrayToolTipOpenEvent; |
1528 |
RoutedEventHelper.RaiseEvent(target, args); |
1529 |
return args; |
1530 |
} |
1531 |
|
1532 |
#endregion |
1533 |
|
1534 |
#region TrayToolTipClose (and PreviewTrayToolTipClose) |
1535 |
|
1536 |
/// <summary> |
1537 |
/// TrayToolTipClose Routed Event |
1538 |
/// </summary> |
1539 |
public static readonly RoutedEvent TrayToolTipCloseEvent = EventManager.RegisterRoutedEvent("TrayToolTipClose", |
1540 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1541 |
|
1542 |
/// <summary> |
1543 |
/// Bubbled event that occurs when a custom tooltip is being closed. |
1544 |
/// </summary> |
1545 |
public event RoutedEventHandler TrayToolTipClose |
1546 |
{ |
1547 |
add { AddHandler(TrayToolTipCloseEvent, value); } |
1548 |
remove { RemoveHandler(TrayToolTipCloseEvent, value); } |
1549 |
} |
1550 |
|
1551 |
/// <summary> |
1552 |
/// A helper method to raise the TrayToolTipClose event. |
1553 |
/// </summary> |
1554 |
protected RoutedEventArgs RaiseTrayToolTipCloseEvent() |
1555 |
{ |
1556 |
return RaiseTrayToolTipCloseEvent(this); |
1557 |
} |
1558 |
|
1559 |
/// <summary> |
1560 |
/// A static helper method to raise the TrayToolTipClose event on a target element. |
1561 |
/// </summary> |
1562 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1563 |
internal static RoutedEventArgs RaiseTrayToolTipCloseEvent(DependencyObject target) |
1564 |
{ |
1565 |
if (target == null) return null; |
1566 |
|
1567 |
RoutedEventArgs args = new RoutedEventArgs(); |
1568 |
args.RoutedEvent = TrayToolTipCloseEvent; |
1569 |
RoutedEventHelper.RaiseEvent(target, args); |
1570 |
return args; |
1571 |
} |
1572 |
|
1573 |
/// <summary> |
1574 |
/// PreviewTrayToolTipClose Routed Event |
1575 |
/// </summary> |
1576 |
public static readonly RoutedEvent PreviewTrayToolTipCloseEvent = |
1577 |
EventManager.RegisterRoutedEvent("PreviewTrayToolTipClose", |
1578 |
RoutingStrategy.Tunnel, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1579 |
|
1580 |
/// <summary> |
1581 |
/// Tunneled event that occurs when a custom tooltip is being closed. |
1582 |
/// </summary> |
1583 |
public event RoutedEventHandler PreviewTrayToolTipClose |
1584 |
{ |
1585 |
add { AddHandler(PreviewTrayToolTipCloseEvent, value); } |
1586 |
remove { RemoveHandler(PreviewTrayToolTipCloseEvent, value); } |
1587 |
} |
1588 |
|
1589 |
/// <summary> |
1590 |
/// A helper method to raise the PreviewTrayToolTipClose event. |
1591 |
/// </summary> |
1592 |
protected RoutedEventArgs RaisePreviewTrayToolTipCloseEvent() |
1593 |
{ |
1594 |
return RaisePreviewTrayToolTipCloseEvent(this); |
1595 |
} |
1596 |
|
1597 |
/// <summary> |
1598 |
/// A static helper method to raise the PreviewTrayToolTipClose event on a target element. |
1599 |
/// </summary> |
1600 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1601 |
internal static RoutedEventArgs RaisePreviewTrayToolTipCloseEvent(DependencyObject target) |
1602 |
{ |
1603 |
if (target == null) return null; |
1604 |
|
1605 |
RoutedEventArgs args = new RoutedEventArgs(); |
1606 |
args.RoutedEvent = PreviewTrayToolTipCloseEvent; |
1607 |
RoutedEventHelper.RaiseEvent(target, args); |
1608 |
return args; |
1609 |
} |
1610 |
|
1611 |
#endregion |
1612 |
|
1613 |
//ATTACHED EVENTS |
1614 |
|
1615 |
#region PopupOpened |
1616 |
|
1617 |
/// <summary> |
1618 |
/// PopupOpened Attached Routed Event |
1619 |
/// </summary> |
1620 |
public static readonly RoutedEvent PopupOpenedEvent = EventManager.RegisterRoutedEvent("PopupOpened", |
1621 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1622 |
|
1623 |
/// <summary> |
1624 |
/// Adds a handler for the PopupOpened attached event |
1625 |
/// </summary> |
1626 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1627 |
/// <param name="handler">Event handler to be added</param> |
1628 |
public static void AddPopupOpenedHandler(DependencyObject element, RoutedEventHandler handler) |
1629 |
{ |
1630 |
RoutedEventHelper.AddHandler(element, PopupOpenedEvent, handler); |
1631 |
} |
1632 |
|
1633 |
/// <summary> |
1634 |
/// Removes a handler for the PopupOpened attached event |
1635 |
/// </summary> |
1636 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1637 |
/// <param name="handler">Event handler to be removed</param> |
1638 |
public static void RemovePopupOpenedHandler(DependencyObject element, RoutedEventHandler handler) |
1639 |
{ |
1640 |
RoutedEventHelper.RemoveHandler(element, PopupOpenedEvent, handler); |
1641 |
} |
1642 |
|
1643 |
/// <summary> |
1644 |
/// A static helper method to raise the PopupOpened event on a target element. |
1645 |
/// </summary> |
1646 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1647 |
internal static RoutedEventArgs RaisePopupOpenedEvent(DependencyObject target) |
1648 |
{ |
1649 |
if (target == null) return null; |
1650 |
|
1651 |
RoutedEventArgs args = new RoutedEventArgs(); |
1652 |
args.RoutedEvent = PopupOpenedEvent; |
1653 |
RoutedEventHelper.RaiseEvent(target, args); |
1654 |
return args; |
1655 |
} |
1656 |
|
1657 |
#endregion |
1658 |
|
1659 |
#region ToolTipOpened |
1660 |
|
1661 |
/// <summary> |
1662 |
/// ToolTipOpened Attached Routed Event |
1663 |
/// </summary> |
1664 |
public static readonly RoutedEvent ToolTipOpenedEvent = EventManager.RegisterRoutedEvent("ToolTipOpened", |
1665 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1666 |
|
1667 |
/// <summary> |
1668 |
/// Adds a handler for the ToolTipOpened attached event |
1669 |
/// </summary> |
1670 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1671 |
/// <param name="handler">Event handler to be added</param> |
1672 |
public static void AddToolTipOpenedHandler(DependencyObject element, RoutedEventHandler handler) |
1673 |
{ |
1674 |
RoutedEventHelper.AddHandler(element, ToolTipOpenedEvent, handler); |
1675 |
} |
1676 |
|
1677 |
/// <summary> |
1678 |
/// Removes a handler for the ToolTipOpened attached event |
1679 |
/// </summary> |
1680 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1681 |
/// <param name="handler">Event handler to be removed</param> |
1682 |
public static void RemoveToolTipOpenedHandler(DependencyObject element, RoutedEventHandler handler) |
1683 |
{ |
1684 |
RoutedEventHelper.RemoveHandler(element, ToolTipOpenedEvent, handler); |
1685 |
} |
1686 |
|
1687 |
/// <summary> |
1688 |
/// A static helper method to raise the ToolTipOpened event on a target element. |
1689 |
/// </summary> |
1690 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1691 |
internal static RoutedEventArgs RaiseToolTipOpenedEvent(DependencyObject target) |
1692 |
{ |
1693 |
if (target == null) return null; |
1694 |
|
1695 |
RoutedEventArgs args = new RoutedEventArgs(); |
1696 |
args.RoutedEvent = ToolTipOpenedEvent; |
1697 |
RoutedEventHelper.RaiseEvent(target, args); |
1698 |
return args; |
1699 |
} |
1700 |
|
1701 |
#endregion |
1702 |
|
1703 |
#region ToolTipClose |
1704 |
|
1705 |
/// <summary> |
1706 |
/// ToolTipClose Attached Routed Event |
1707 |
/// </summary> |
1708 |
public static readonly RoutedEvent ToolTipCloseEvent = EventManager.RegisterRoutedEvent("ToolTipClose", |
1709 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1710 |
|
1711 |
/// <summary> |
1712 |
/// Adds a handler for the ToolTipClose attached event |
1713 |
/// </summary> |
1714 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1715 |
/// <param name="handler">Event handler to be added</param> |
1716 |
public static void AddToolTipCloseHandler(DependencyObject element, RoutedEventHandler handler) |
1717 |
{ |
1718 |
RoutedEventHelper.AddHandler(element, ToolTipCloseEvent, handler); |
1719 |
} |
1720 |
|
1721 |
/// <summary> |
1722 |
/// Removes a handler for the ToolTipClose attached event |
1723 |
/// </summary> |
1724 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1725 |
/// <param name="handler">Event handler to be removed</param> |
1726 |
public static void RemoveToolTipCloseHandler(DependencyObject element, RoutedEventHandler handler) |
1727 |
{ |
1728 |
RoutedEventHelper.RemoveHandler(element, ToolTipCloseEvent, handler); |
1729 |
} |
1730 |
|
1731 |
/// <summary> |
1732 |
/// A static helper method to raise the ToolTipClose event on a target element. |
1733 |
/// </summary> |
1734 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1735 |
internal static RoutedEventArgs RaiseToolTipCloseEvent(DependencyObject target) |
1736 |
{ |
1737 |
if (target == null) return null; |
1738 |
|
1739 |
RoutedEventArgs args = new RoutedEventArgs(); |
1740 |
args.RoutedEvent = ToolTipCloseEvent; |
1741 |
RoutedEventHelper.RaiseEvent(target, args); |
1742 |
return args; |
1743 |
} |
1744 |
|
1745 |
#endregion |
1746 |
|
1747 |
#region BalloonShowing |
1748 |
|
1749 |
/// <summary> |
1750 |
/// BalloonShowing Attached Routed Event |
1751 |
/// </summary> |
1752 |
public static readonly RoutedEvent BalloonShowingEvent = EventManager.RegisterRoutedEvent("BalloonShowing", |
1753 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1754 |
|
1755 |
/// <summary> |
1756 |
/// Adds a handler for the BalloonShowing attached event |
1757 |
/// </summary> |
1758 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1759 |
/// <param name="handler">Event handler to be added</param> |
1760 |
public static void AddBalloonShowingHandler(DependencyObject element, RoutedEventHandler handler) |
1761 |
{ |
1762 |
RoutedEventHelper.AddHandler(element, BalloonShowingEvent, handler); |
1763 |
} |
1764 |
|
1765 |
/// <summary> |
1766 |
/// Removes a handler for the BalloonShowing attached event |
1767 |
/// </summary> |
1768 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1769 |
/// <param name="handler">Event handler to be removed</param> |
1770 |
public static void RemoveBalloonShowingHandler(DependencyObject element, RoutedEventHandler handler) |
1771 |
{ |
1772 |
RoutedEventHelper.RemoveHandler(element, BalloonShowingEvent, handler); |
1773 |
} |
1774 |
|
1775 |
/// <summary> |
1776 |
/// A static helper method to raise the BalloonShowing event on a target element. |
1777 |
/// </summary> |
1778 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1779 |
/// <param name="source">The <see cref="TaskbarIcon"/> instance that manages the balloon.</param> |
1780 |
internal static RoutedEventArgs RaiseBalloonShowingEvent(DependencyObject target, TaskbarIcon source) |
1781 |
{ |
1782 |
if (target == null) return null; |
1783 |
|
1784 |
RoutedEventArgs args = new RoutedEventArgs(BalloonShowingEvent, source); |
1785 |
RoutedEventHelper.RaiseEvent(target, args); |
1786 |
return args; |
1787 |
} |
1788 |
|
1789 |
#endregion |
1790 |
|
1791 |
#region BalloonClosing |
1792 |
|
1793 |
/// <summary> |
1794 |
/// BalloonClosing Attached Routed Event |
1795 |
/// </summary> |
1796 |
public static readonly RoutedEvent BalloonClosingEvent = EventManager.RegisterRoutedEvent("BalloonClosing", |
1797 |
RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (TaskbarIcon)); |
1798 |
|
1799 |
/// <summary> |
1800 |
/// Adds a handler for the BalloonClosing attached event |
1801 |
/// </summary> |
1802 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1803 |
/// <param name="handler">Event handler to be added</param> |
1804 |
public static void AddBalloonClosingHandler(DependencyObject element, RoutedEventHandler handler) |
1805 |
{ |
1806 |
RoutedEventHelper.AddHandler(element, BalloonClosingEvent, handler); |
1807 |
} |
1808 |
|
1809 |
/// <summary> |
1810 |
/// Removes a handler for the BalloonClosing attached event |
1811 |
/// </summary> |
1812 |
/// <param name="element">UIElement or ContentElement that listens to the event</param> |
1813 |
/// <param name="handler">Event handler to be removed</param> |
1814 |
public static void RemoveBalloonClosingHandler(DependencyObject element, RoutedEventHandler handler) |
1815 |
{ |
1816 |
RoutedEventHelper.RemoveHandler(element, BalloonClosingEvent, handler); |
1817 |
} |
1818 |
|
1819 |
/// <summary> |
1820 |
/// A static helper method to raise the BalloonClosing event on a target element. |
1821 |
/// </summary> |
1822 |
/// <param name="target">UIElement or ContentElement on which to raise the event</param> |
1823 |
/// <param name="source">The <see cref="TaskbarIcon"/> instance that manages the balloon.</param> |
1824 |
internal static RoutedEventArgs RaiseBalloonClosingEvent(DependencyObject target, TaskbarIcon source) |
1825 |
{ |
1826 |
if (target == null) return null; |
1827 |
|
1828 |
RoutedEventArgs args = new RoutedEventArgs(BalloonClosingEvent, source); |
1829 |
RoutedEventHelper.RaiseEvent(target, args); |
1830 |
return args; |
1831 |
} |
1832 |
|
1833 |
#endregion |
1834 |
|
1835 |
//ATTACHED PROPERTIES |
1836 |
|
1837 |
#region ParentTaskbarIcon |
1838 |
|
1839 |
/// <summary> |
1840 |
/// An attached property that is assigned to displayed UI elements (balloos, tooltips, context menus), and |
1841 |
/// that can be used to bind to this control. The attached property is being derived, so binding is |
1842 |
/// quite straightforward: |
1843 |
/// <code> |
1844 |
/// <TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=(tb:TaskbarIcon.ParentTaskbarIcon).ToolTipText}" /> |
1845 |
/// </code> |
1846 |
/// </summary> |
1847 |
public static readonly DependencyProperty ParentTaskbarIconProperty = |
1848 |
DependencyProperty.RegisterAttached("ParentTaskbarIcon", typeof (TaskbarIcon), typeof (TaskbarIcon), |
1849 |
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); |
1850 |
|
1851 |
/// <summary> |
1852 |
/// Gets the ParentTaskbarIcon property. This dependency property |
1853 |
/// indicates .... |
1854 |
/// </summary> |
1855 |
public static TaskbarIcon GetParentTaskbarIcon(DependencyObject d) |
1856 |
{ |
1857 |
return (TaskbarIcon) d.GetValue(ParentTaskbarIconProperty); |
1858 |
} |
1859 |
|
1860 |
/// <summary> |
1861 |
/// Sets the ParentTaskbarIcon property. This dependency property |
1862 |
/// indicates .... |
1863 |
/// </summary> |
1864 |
public static void SetParentTaskbarIcon(DependencyObject d, TaskbarIcon value) |
1865 |
{ |
1866 |
d.SetValue(ParentTaskbarIconProperty, value); |
1867 |
} |
1868 |
|
1869 |
#endregion |
1870 |
|
1871 |
//BASE CLASS PROPERTY OVERRIDES |
1872 |
|
1873 |
/// <summary> |
1874 |
/// Registers properties. |
1875 |
/// </summary> |
1876 |
static TaskbarIcon() |
1877 |
{ |
1878 |
//register change listener for the Visibility property |
1879 |
var md = new PropertyMetadata(Visibility.Visible, VisibilityPropertyChanged); |
1880 |
VisibilityProperty.OverrideMetadata(typeof (TaskbarIcon), md); |
1881 |
|
1882 |
//register change listener for the DataContext property |
1883 |
md = new FrameworkPropertyMetadata(new PropertyChangedCallback(DataContextPropertyChanged)); |
1884 |
DataContextProperty.OverrideMetadata(typeof (TaskbarIcon), md); |
1885 |
|
1886 |
//register change listener for the ContextMenu property |
1887 |
md = new FrameworkPropertyMetadata(new PropertyChangedCallback(ContextMenuPropertyChanged)); |
1888 |
ContextMenuProperty.OverrideMetadata(typeof (TaskbarIcon), md); |
1889 |
} |
1890 |
} |
1891 |
} |