TaskbarIcon.Declarations.cs 76 KB

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