using System; using System.Drawing; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; using Hardcodet.Wpf.TaskbarNotification.Interop; namespace Hardcodet.Wpf.TaskbarNotification { /// /// Contains declarations of WPF dependency properties /// and events. /// partial class TaskbarIcon { //DEPENDENCY PROPERTIES #region ToolTipText dependency property /// /// A tooltip text that is being displayed if no custom /// was set or if custom tooltips are not supported. /// public static readonly DependencyProperty ToolTipTextProperty = DependencyProperty.Register("ToolTipText", typeof (string), typeof (TaskbarIcon), new FrameworkPropertyMetadata(String.Empty, ToolTipTextPropertyChanged)); /// /// A property wrapper for the /// dependency property:
/// A tooltip text that is being displayed if no custom /// was set or if custom tooltips are not supported. ///
public string ToolTipText { get { return (string) GetValue(ToolTipTextProperty); } set { SetValue(ToolTipTextProperty, value); } } /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void ToolTipTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnToolTipTextPropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnToolTipTextPropertyChanged(DependencyPropertyChangedEventArgs e) { string newValue = (string) e.NewValue; iconData.ToolTipText = newValue ?? String.Empty; WriteToolTipSettings(); } #endregion #region ToolTip dependency property override /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void ToolTipPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnToolTipPropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnToolTipPropertyChanged(DependencyPropertyChangedEventArgs e) { if (e.NewValue != null) { ToolTip tt = e.NewValue as ToolTip; if (tt == null) { tt = new ToolTip(); tt.Content = e.NewValue; ToolTip = tt; return; } } WriteToolTipSettings(); } #endregion #region Icon property / IconSource dependency property private Icon icon; /// /// Gets or sets the icon to be displayed. This is not a /// dependency property - if you want to assign the property /// through XAML, please use the /// dependency property. /// public Icon Icon { get { return icon; } set { icon = value; iconData.IconHandle = value == null ? IntPtr.Zero : icon.Handle; Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Icon); } } /// /// Resolves an image source and updates the property accordingly. /// public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register("IconSource", typeof (ImageSource), typeof (TaskbarIcon), new FrameworkPropertyMetadata(null, IconSourcePropertyChanged)); /// /// A property wrapper for the /// dependency property:
/// Resolves an image source and updates the property accordingly. ///
public ImageSource IconSource { get { return (ImageSource) GetValue(IconSourceProperty); } set { SetValue(IconSourceProperty, value); } } /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void IconSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnIconSourcePropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnIconSourcePropertyChanged(DependencyPropertyChangedEventArgs e) { ImageSource newValue = (ImageSource) e.NewValue; Icon = newValue.ToIcon(); } #endregion #region TaskbarIconPopup dependency property /// /// A custom popup that is displayed when the taskbar icon is clicked. /// public static readonly DependencyProperty TaskbarIconPopupProperty = DependencyProperty.Register("TaskbarIconPopup", typeof (Popup), typeof (TaskbarIcon), new FrameworkPropertyMetadata(null, TaskbarIconPopupPropertyChanged)); /// /// A property wrapper for the /// dependency property:
/// A custom popup that is displayed when the taskbar icon is clicked. ///
public Popup TaskbarIconPopup { get { return (Popup) GetValue(TaskbarIconPopupProperty); } set { SetValue(TaskbarIconPopupProperty, value); } } /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void TaskbarIconPopupPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnTaskbarIconPopupPropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnTaskbarIconPopupPropertyChanged(DependencyPropertyChangedEventArgs e) { //currently not needed } #endregion #region MenuActivation dependency property /// /// Defines what mouse events display the context menu. /// Defaults to . /// public static readonly DependencyProperty MenuActivationProperty = DependencyProperty.Register("MenuActivation", typeof (PopupActivationMode), typeof (TaskbarIcon), new FrameworkPropertyMetadata(PopupActivationMode.RightClick, MenuActivationPropertyChanged)); /// /// A property wrapper for the /// dependency property:
/// Defines what mouse events display the context menu. /// Defaults to . ///
public PopupActivationMode MenuActivation { get { return (PopupActivationMode) GetValue(MenuActivationProperty); } set { SetValue(MenuActivationProperty, value); } } /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void MenuActivationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnMenuActivationPropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnMenuActivationPropertyChanged(DependencyPropertyChangedEventArgs e) { //currently not needed } #endregion #region PopupActivation dependency property /// /// Defines what mouse events trigger the . /// Default is . /// public static readonly DependencyProperty PopupActivationProperty = DependencyProperty.Register("PopupActivation", typeof (PopupActivationMode), typeof (TaskbarIcon), new FrameworkPropertyMetadata(PopupActivationMode.LeftClick, PopupActivationPropertyChanged)); /// /// A property wrapper for the /// dependency property:
/// Defines what mouse events trigger the . /// Default is . ///
public PopupActivationMode PopupActivation { get { return (PopupActivationMode) GetValue(PopupActivationProperty); } set { SetValue(PopupActivationProperty, value); } } /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void PopupActivationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnPopupActivationPropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnPopupActivationPropertyChanged(DependencyPropertyChangedEventArgs e) { //currently not needed } #endregion #region Visibility dependency property override /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void VisibilityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnVisibilityPropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnVisibilityPropertyChanged(DependencyPropertyChangedEventArgs e) { Visibility newValue = (Visibility) e.NewValue; //update if (newValue == Visibility.Visible) { CreateTaskbarIcon(); } else { RemoveTaskbarIcon(); } } #endregion #region ContextMenu dependency property override /// /// A static callback listener which is being invoked if the /// dependency property has /// been changed. Invokes the /// instance method of the changed instance. /// /// The currently processed owner of the property. /// Provides information about the updated property. private static void ContextMenuPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskbarIcon owner = (TaskbarIcon) d; owner.OnContextMenuPropertyChanged(e); } /// /// Handles changes of the dependency property. As /// WPF internally uses the dependency property system and bypasses the /// property wrapper, updates of the property's value /// should be handled here. /// Provides information about the updated property. private void OnContextMenuPropertyChanged(DependencyPropertyChangedEventArgs e) { //currently not needed } #endregion //EVENTS #region TaskbarIconLeftMouseDown /// /// TaskbarIconLeftMouseDown Routed Event /// public static readonly RoutedEvent TaskbarIconLeftMouseDownEvent = EventManager.RegisterRoutedEvent("TaskbarIconLeftMouseDown", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user presses the left mouse button. /// public event RoutedEventHandler TaskbarIconLeftMouseDown { add { AddHandler(TaskbarIconLeftMouseDownEvent, value); } remove { RemoveHandler(TaskbarIconLeftMouseDownEvent, value); } } /// /// A helper method to raise the TaskbarIconLeftMouseDown event. /// protected RoutedEventArgs RaiseTaskbarIconLeftMouseDownEvent() { return RaiseTaskbarIconLeftMouseDownEvent(this); } /// /// A static helper method to raise the TaskbarIconLeftMouseDown event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconLeftMouseDownEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconLeftMouseDownEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconRightMouseDown /// /// TaskbarIconRightMouseDown Routed Event /// public static readonly RoutedEvent TaskbarIconRightMouseDownEvent = EventManager.RegisterRoutedEvent("TaskbarIconRightMouseDown", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the presses the right mouse button. /// public event RoutedEventHandler TaskbarIconRightMouseDown { add { AddHandler(TaskbarIconRightMouseDownEvent, value); } remove { RemoveHandler(TaskbarIconRightMouseDownEvent, value); } } /// /// A helper method to raise the TaskbarIconRightMouseDown event. /// protected RoutedEventArgs RaiseTaskbarIconRightMouseDownEvent() { return RaiseTaskbarIconRightMouseDownEvent(this); } /// /// A static helper method to raise the TaskbarIconRightMouseDown event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconRightMouseDownEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconRightMouseDownEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconMiddleMouseDown /// /// TaskbarIconMiddleMouseDown Routed Event /// public static readonly RoutedEvent TaskbarIconMiddleMouseDownEvent = EventManager.RegisterRoutedEvent("TaskbarIconMiddleMouseDown", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user presses the middle mouse button. /// public event RoutedEventHandler TaskbarIconMiddleMouseDown { add { AddHandler(TaskbarIconMiddleMouseDownEvent, value); } remove { RemoveHandler(TaskbarIconMiddleMouseDownEvent, value); } } /// /// A helper method to raise the TaskbarIconMiddleMouseDown event. /// protected RoutedEventArgs RaiseTaskbarIconMiddleMouseDownEvent() { return RaiseTaskbarIconMiddleMouseDownEvent(this); } /// /// A static helper method to raise the TaskbarIconMiddleMouseDown event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconMiddleMouseDownEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconMiddleMouseDownEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconLeftMouseUp /// /// TaskbarIconLeftMouseUp Routed Event /// public static readonly RoutedEvent TaskbarIconLeftMouseUpEvent = EventManager.RegisterRoutedEvent("TaskbarIconLeftMouseUp", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user releases the left mouse button. /// public event RoutedEventHandler TaskbarIconLeftMouseUp { add { AddHandler(TaskbarIconLeftMouseUpEvent, value); } remove { RemoveHandler(TaskbarIconLeftMouseUpEvent, value); } } /// /// A helper method to raise the TaskbarIconLeftMouseUp event. /// protected RoutedEventArgs RaiseTaskbarIconLeftMouseUpEvent() { return RaiseTaskbarIconLeftMouseUpEvent(this); } /// /// A static helper method to raise the TaskbarIconLeftMouseUp event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconLeftMouseUpEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconLeftMouseUpEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconRightMouseUp /// /// TaskbarIconRightMouseUp Routed Event /// public static readonly RoutedEvent TaskbarIconRightMouseUpEvent = EventManager.RegisterRoutedEvent("TaskbarIconRightMouseUp", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user releases the right mouse button. /// public event RoutedEventHandler TaskbarIconRightMouseUp { add { AddHandler(TaskbarIconRightMouseUpEvent, value); } remove { RemoveHandler(TaskbarIconRightMouseUpEvent, value); } } /// /// A helper method to raise the TaskbarIconRightMouseUp event. /// protected RoutedEventArgs RaiseTaskbarIconRightMouseUpEvent() { return RaiseTaskbarIconRightMouseUpEvent(this); } /// /// A static helper method to raise the TaskbarIconRightMouseUp event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconRightMouseUpEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconRightMouseUpEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconMiddleMouseUp /// /// TaskbarIconMiddleMouseUp Routed Event /// public static readonly RoutedEvent TaskbarIconMiddleMouseUpEvent = EventManager.RegisterRoutedEvent("TaskbarIconMiddleMouseUp", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user releases the middle mouse button. /// public event RoutedEventHandler TaskbarIconMiddleMouseUp { add { AddHandler(TaskbarIconMiddleMouseUpEvent, value); } remove { RemoveHandler(TaskbarIconMiddleMouseUpEvent, value); } } /// /// A helper method to raise the TaskbarIconMiddleMouseUp event. /// protected RoutedEventArgs RaiseTaskbarIconMiddleMouseUpEvent() { return RaiseTaskbarIconMiddleMouseUpEvent(this); } /// /// A static helper method to raise the TaskbarIconMiddleMouseUp event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconMiddleMouseUpEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconMiddleMouseUpEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconMouseDoubleClick /// /// TaskbarIconMouseDoubleClick Routed Event /// public static readonly RoutedEvent TaskbarIconMouseDoubleClickEvent = EventManager.RegisterRoutedEvent("TaskbarIconMouseDoubleClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user double-clicks the taskbar icon. /// public event RoutedEventHandler TaskbarIconMouseDoubleClick { add { AddHandler(TaskbarIconMouseDoubleClickEvent, value); } remove { RemoveHandler(TaskbarIconMouseDoubleClickEvent, value); } } /// /// A helper method to raise the TaskbarIconMouseDoubleClick event. /// protected RoutedEventArgs RaiseTaskbarIconMouseDoubleClickEvent() { return RaiseTaskbarIconMouseDoubleClickEvent(this); } /// /// A static helper method to raise the TaskbarIconMouseDoubleClick event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconMouseDoubleClickEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconMouseDoubleClickEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconMouseMove /// /// TaskbarIconMouseMove Routed Event /// public static readonly RoutedEvent TaskbarIconMouseMoveEvent = EventManager.RegisterRoutedEvent("TaskbarIconMouseMove", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user moves the mouse over the taskbar icon. /// public event RoutedEventHandler TaskbarIconMouseMove { add { AddHandler(TaskbarIconMouseMoveEvent, value); } remove { RemoveHandler(TaskbarIconMouseMoveEvent, value); } } /// /// A helper method to raise the TaskbarIconMouseMove event. /// protected RoutedEventArgs RaiseTaskbarIconMouseMoveEvent() { return RaiseTaskbarIconMouseMoveEvent(this); } /// /// A static helper method to raise the TaskbarIconMouseMove event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconMouseMoveEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconMouseMoveEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconBalloonTipShown /// /// TaskbarIconBalloonTipShown Routed Event /// public static readonly RoutedEvent TaskbarIconBalloonTipShownEvent = EventManager.RegisterRoutedEvent("TaskbarIconBalloonTipShown", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when a balloon ToolTip is displayed. /// public event RoutedEventHandler TaskbarIconBalloonTipShown { add { AddHandler(TaskbarIconBalloonTipShownEvent, value); } remove { RemoveHandler(TaskbarIconBalloonTipShownEvent, value); } } /// /// A helper method to raise the TaskbarIconBalloonTipShown event. /// protected RoutedEventArgs RaiseTaskbarIconBalloonTipShownEvent() { return RaiseTaskbarIconBalloonTipShownEvent(this); } /// /// A static helper method to raise the TaskbarIconBalloonTipShown event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconBalloonTipShownEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconBalloonTipShownEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconBalloonTipClosed /// /// TaskbarIconBalloonTipClosed Routed Event /// public static readonly RoutedEvent TaskbarIconBalloonTipClosedEvent = EventManager.RegisterRoutedEvent("TaskbarIconBalloonTipClosed", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when a balloon ToolTip was closed. /// public event RoutedEventHandler TaskbarIconBalloonTipClosed { add { AddHandler(TaskbarIconBalloonTipClosedEvent, value); } remove { RemoveHandler(TaskbarIconBalloonTipClosedEvent, value); } } /// /// A helper method to raise the TaskbarIconBalloonTipClosed event. /// protected RoutedEventArgs RaiseTaskbarIconBalloonTipClosedEvent() { return RaiseTaskbarIconBalloonTipClosedEvent(this); } /// /// A static helper method to raise the TaskbarIconBalloonTipClosed event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconBalloonTipClosedEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconBalloonTipClosedEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconBalloonTipClicked /// /// TaskbarIconBalloonTipClicked Routed Event /// public static readonly RoutedEvent TaskbarIconBalloonTipClickedEvent = EventManager.RegisterRoutedEvent("TaskbarIconBalloonTipClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Occurs when the user clicks on a balloon ToolTip. /// public event RoutedEventHandler TaskbarIconBalloonTipClicked { add { AddHandler(TaskbarIconBalloonTipClickedEvent, value); } remove { RemoveHandler(TaskbarIconBalloonTipClickedEvent, value); } } /// /// A helper method to raise the TaskbarIconBalloonTipClicked event. /// protected RoutedEventArgs RaiseTaskbarIconBalloonTipClickedEvent() { return RaiseTaskbarIconBalloonTipClickedEvent(this); } /// /// A static helper method to raise the TaskbarIconBalloonTipClicked event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconBalloonTipClickedEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconBalloonTipClickedEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconContextMenuOpen (and PreviewTaskbarIconContextMenuOpen) /// /// TaskbarIconContextMenuOpen Routed Event /// public static readonly RoutedEvent TaskbarIconContextMenuOpenEvent = EventManager.RegisterRoutedEvent("TaskbarIconContextMenuOpen", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Bubbled event that occurs when the context menu of the taskbar icon is being displayed. /// public event RoutedEventHandler TaskbarIconContextMenuOpen { add { AddHandler(TaskbarIconContextMenuOpenEvent, value); } remove { RemoveHandler(TaskbarIconContextMenuOpenEvent, value); } } /// /// A helper method to raise the TaskbarIconContextMenuOpen event. /// protected RoutedEventArgs RaiseTaskbarIconContextMenuOpenEvent() { return RaiseTaskbarIconContextMenuOpenEvent(this); } /// /// A static helper method to raise the TaskbarIconContextMenuOpen event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconContextMenuOpenEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconContextMenuOpenEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } /// /// PreviewTaskbarIconContextMenuOpen Routed Event /// public static readonly RoutedEvent PreviewTaskbarIconContextMenuOpenEvent = EventManager.RegisterRoutedEvent("PreviewTaskbarIconContextMenuOpen", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Tunneled event that occurs when the context menu of the taskbar icon is being displayed. /// public event RoutedEventHandler PreviewTaskbarIconContextMenuOpen { add { AddHandler(PreviewTaskbarIconContextMenuOpenEvent, value); } remove { RemoveHandler(PreviewTaskbarIconContextMenuOpenEvent, value); } } /// /// A helper method to raise the PreviewTaskbarIconContextMenuOpen event. /// protected RoutedEventArgs RaisePreviewTaskbarIconContextMenuOpenEvent() { return RaisePreviewTaskbarIconContextMenuOpenEvent(this); } /// /// A static helper method to raise the PreviewTaskbarIconContextMenuOpen event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaisePreviewTaskbarIconContextMenuOpenEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = PreviewTaskbarIconContextMenuOpenEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconPopupOpen (and PreviewTaskbarIconPopupOpen) /// /// TaskbarIconPopupOpen Routed Event /// public static readonly RoutedEvent TaskbarIconPopupOpenEvent = EventManager.RegisterRoutedEvent("TaskbarIconPopupOpen", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Bubbled event that occurs when the custom popup is being opened. /// public event RoutedEventHandler TaskbarIconPopupOpen { add { AddHandler(TaskbarIconPopupOpenEvent, value); } remove { RemoveHandler(TaskbarIconPopupOpenEvent, value); } } /// /// A helper method to raise the TaskbarIconPopupOpen event. /// protected RoutedEventArgs RaiseTaskbarIconPopupOpenEvent() { return RaiseTaskbarIconPopupOpenEvent(this); } /// /// A static helper method to raise the TaskbarIconPopupOpen event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconPopupOpenEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconPopupOpenEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } /// /// PreviewTaskbarIconPopupOpen Routed Event /// public static readonly RoutedEvent PreviewTaskbarIconPopupOpenEvent = EventManager.RegisterRoutedEvent("PreviewTaskbarIconPopupOpen", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Tunneled event that occurs when the custom popup is being opened. /// public event RoutedEventHandler PreviewTaskbarIconPopupOpen { add { AddHandler(PreviewTaskbarIconPopupOpenEvent, value); } remove { RemoveHandler(PreviewTaskbarIconPopupOpenEvent, value); } } /// /// A helper method to raise the PreviewTaskbarIconPopupOpen event. /// protected RoutedEventArgs RaisePreviewTaskbarIconPopupOpenEvent() { return RaisePreviewTaskbarIconPopupOpenEvent(this); } /// /// A static helper method to raise the PreviewTaskbarIconPopupOpen event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaisePreviewTaskbarIconPopupOpenEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = PreviewTaskbarIconPopupOpenEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconToolTipOpen (and PreviewTaskbarIconToolTipOpen) /// /// TaskbarIconToolTipOpen Routed Event /// public static readonly RoutedEvent TaskbarIconToolTipOpenEvent = EventManager.RegisterRoutedEvent("TaskbarIconToolTipOpen", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Bubbled event that occurs when the custom ToolTip is being displayed. /// public event RoutedEventHandler TaskbarIconToolTipOpen { add { AddHandler(TaskbarIconToolTipOpenEvent, value); } remove { RemoveHandler(TaskbarIconToolTipOpenEvent, value); } } /// /// A helper method to raise the TaskbarIconToolTipOpen event. /// protected RoutedEventArgs RaiseTaskbarIconToolTipOpenEvent() { return RaiseTaskbarIconToolTipOpenEvent(this); } /// /// A static helper method to raise the TaskbarIconToolTipOpen event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconToolTipOpenEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconToolTipOpenEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } /// /// PreviewTaskbarIconToolTipOpen Routed Event /// public static readonly RoutedEvent PreviewTaskbarIconToolTipOpenEvent = EventManager.RegisterRoutedEvent("PreviewTaskbarIconToolTipOpen", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Tunneled event that occurs when the custom ToolTip is being displayed. /// public event RoutedEventHandler PreviewTaskbarIconToolTipOpen { add { AddHandler(PreviewTaskbarIconToolTipOpenEvent, value); } remove { RemoveHandler(PreviewTaskbarIconToolTipOpenEvent, value); } } /// /// A helper method to raise the PreviewTaskbarIconToolTipOpen event. /// protected RoutedEventArgs RaisePreviewTaskbarIconToolTipOpenEvent() { return RaisePreviewTaskbarIconToolTipOpenEvent(this); } /// /// A static helper method to raise the PreviewTaskbarIconToolTipOpen event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaisePreviewTaskbarIconToolTipOpenEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = PreviewTaskbarIconToolTipOpenEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion #region TaskbarIconToolTipClose (and PreviewTaskbarIconToolTipClose) /// /// TaskbarIconToolTipClose Routed Event /// public static readonly RoutedEvent TaskbarIconToolTipCloseEvent = EventManager.RegisterRoutedEvent("TaskbarIconToolTipClose", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Bubbled event that occurs when a custom tooltip is being closed. /// public event RoutedEventHandler TaskbarIconToolTipClose { add { AddHandler(TaskbarIconToolTipCloseEvent, value); } remove { RemoveHandler(TaskbarIconToolTipCloseEvent, value); } } /// /// A helper method to raise the TaskbarIconToolTipClose event. /// protected RoutedEventArgs RaiseTaskbarIconToolTipCloseEvent() { return RaiseTaskbarIconToolTipCloseEvent(this); } /// /// A static helper method to raise the TaskbarIconToolTipClose event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaiseTaskbarIconToolTipCloseEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = TaskbarIconToolTipCloseEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } /// /// PreviewTaskbarIconToolTipClose Routed Event /// public static readonly RoutedEvent PreviewTaskbarIconToolTipCloseEvent = EventManager.RegisterRoutedEvent("PreviewTaskbarIconToolTipClose", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(TaskbarIcon)); /// /// Tunneled event that occurs when a custom tooltip is being closed. /// public event RoutedEventHandler PreviewTaskbarIconToolTipClose { add { AddHandler(PreviewTaskbarIconToolTipCloseEvent, value); } remove { RemoveHandler(PreviewTaskbarIconToolTipCloseEvent, value); } } /// /// A helper method to raise the PreviewTaskbarIconToolTipClose event. /// protected RoutedEventArgs RaisePreviewTaskbarIconToolTipCloseEvent() { return RaisePreviewTaskbarIconToolTipCloseEvent(this); } /// /// A static helper method to raise the PreviewTaskbarIconToolTipClose event on a target element. /// /// UIElement or ContentElement on which to raise the event internal static RoutedEventArgs RaisePreviewTaskbarIconToolTipCloseEvent(DependencyObject target) { if (target == null) return null; RoutedEventArgs args = new RoutedEventArgs(); args.RoutedEvent = PreviewTaskbarIconToolTipCloseEvent; RoutedEventHelper.RaiseEvent(target, args); return args; } #endregion //BASE CLASS PROPERTY OVERRIDES /// /// Registers properties. /// static TaskbarIcon() { //register change listener for the Visibility property PropertyMetadata md = new PropertyMetadata(Visibility.Visible, VisibilityPropertyChanged); VisibilityProperty.OverrideMetadata(typeof(TaskbarIcon), md); //register change listener for the ContextMenu property md = new FrameworkPropertyMetadata(new PropertyChangedCallback(ContextMenuPropertyChanged)); ContextMenuProperty.OverrideMetadata(typeof (TaskbarIcon), md); //register change listener for the ToolTip property md = new FrameworkPropertyMetadata(new PropertyChangedCallback(ToolTipPropertyChanged)); ToolTipProperty.OverrideMetadata(typeof(TaskbarIcon), md); } } }