mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-02-16 11:08:30 -05:00
NotifyIcon WPF
-------------- CHG Merged partial classes of TaskbarIcon - no only 2 files. ADD Added attached events that indicate an opened popup/tooltip ADD Added storyboards in samples that make use of attached events. git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@56 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
@@ -58,7 +58,6 @@
|
|||||||
<Compile Include="Interop\WindowClass.cs" />
|
<Compile Include="Interop\WindowClass.cs" />
|
||||||
<Compile Include="PopupActivationMode.cs" />
|
<Compile Include="PopupActivationMode.cs" />
|
||||||
<Compile Include="RoutedEventHelper.cs" />
|
<Compile Include="RoutedEventHelper.cs" />
|
||||||
<Compile Include="TaskbarIcon.Interop.cs" />
|
|
||||||
<Compile Include="Interop\WinApi.cs" />
|
<Compile Include="Interop\WinApi.cs" />
|
||||||
<Compile Include="Interop\MouseEvent.cs" />
|
<Compile Include="Interop\MouseEvent.cs" />
|
||||||
<Compile Include="Interop\NotifyCommand.cs" />
|
<Compile Include="Interop\NotifyCommand.cs" />
|
||||||
|
|||||||
@@ -25,14 +25,98 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// in order to display either <see cref="TaskbarIconToolTip"/>
|
/// in order to display either <see cref="TaskbarIconToolTip"/>
|
||||||
/// or <see cref="ToolTipText"/>.
|
/// or <see cref="ToolTipText"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ToolTip CustomToolTip { get; private set; }
|
internal ToolTip CustomToolTip
|
||||||
|
{
|
||||||
|
get { return IconToolTipResolved; }
|
||||||
|
private set { SetIconToolTipResolved(value); }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A <see cref="Popup"/> which is either the
|
/// A <see cref="Popup"/> which is either the
|
||||||
/// <see cref="TaskbarIconPopup"/> control itself or a
|
/// <see cref="TaskbarIconPopup"/> control itself or a
|
||||||
/// <see cref="Popup"/> that wraps it.
|
/// <see cref="Popup"/> that wraps it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal Popup CustomPopup { get; private set; }
|
internal Popup CustomPopup
|
||||||
|
{
|
||||||
|
get { return IconPopupResolved; }
|
||||||
|
private set { SetIconPopupResolved(value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//RESOLVED POPUPS CONTROLS
|
||||||
|
#region IconPopupResolved
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// IconPopupResolved Read-Only Dependency Property
|
||||||
|
/// </summary>
|
||||||
|
private static readonly DependencyPropertyKey IconPopupResolvedPropertyKey
|
||||||
|
= DependencyProperty.RegisterReadOnly("IconPopupResolved", typeof(Popup), typeof(TaskbarIcon),
|
||||||
|
new FrameworkPropertyMetadata(null));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IconPopupResolvedProperty
|
||||||
|
= IconPopupResolvedPropertyKey.DependencyProperty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the IconPopupResolved property. This dependency property
|
||||||
|
/// indicates ....
|
||||||
|
/// </summary>
|
||||||
|
[Category(CategoryName)]
|
||||||
|
public Popup IconPopupResolved
|
||||||
|
{
|
||||||
|
get { return (Popup)GetValue(IconPopupResolvedProperty); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a secure method for setting the IconPopupResolved property.
|
||||||
|
/// This dependency property indicates ....
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new value for the property.</param>
|
||||||
|
protected void SetIconPopupResolved(Popup value)
|
||||||
|
{
|
||||||
|
SetValue(IconPopupResolvedPropertyKey, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IconToolTipResolved
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// IconToolTipResolved Read-Only Dependency Property
|
||||||
|
/// </summary>
|
||||||
|
private static readonly DependencyPropertyKey IconToolTipResolvedPropertyKey
|
||||||
|
= DependencyProperty.RegisterReadOnly("IconToolTipResolved", typeof(ToolTip), typeof(TaskbarIcon),
|
||||||
|
new FrameworkPropertyMetadata(null ));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IconToolTipResolvedProperty
|
||||||
|
= IconToolTipResolvedPropertyKey.DependencyProperty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the IconToolTipResolved property. This dependency property
|
||||||
|
/// indicates ....
|
||||||
|
/// </summary>
|
||||||
|
[Category(CategoryName)]
|
||||||
|
[Browsable(true)]
|
||||||
|
[Bindable(true)]
|
||||||
|
public ToolTip IconToolTipResolved
|
||||||
|
{
|
||||||
|
get { return (ToolTip)GetValue(IconToolTipResolvedProperty); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a secure method for setting the IconToolTipResolved property.
|
||||||
|
/// This dependency property indicates ....
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new value for the property.</param>
|
||||||
|
protected void SetIconToolTipResolved(ToolTip value)
|
||||||
|
{
|
||||||
|
SetValue(IconToolTipResolvedPropertyKey, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//DEPENDENCY PROPERTIES
|
//DEPENDENCY PROPERTIES
|
||||||
@@ -292,7 +376,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <param name="e">Provides information about the updated property.</param>
|
/// <param name="e">Provides information about the updated property.</param>
|
||||||
private void OnTaskbarIconPopupPropertyChanged(DependencyPropertyChangedEventArgs e)
|
private void OnTaskbarIconPopupPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
//currently not needed
|
//create a pop
|
||||||
CreatePopup();
|
CreatePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,38 +537,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ContextMenu dependency property override
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A static callback listener which is being invoked if the
|
|
||||||
/// <see cref="FrameworkElement.ContextMenuProperty"/> dependency property has
|
|
||||||
/// been changed. Invokes the <see cref="OnContextMenuPropertyChanged"/>
|
|
||||||
/// instance method of the changed instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="d">The currently processed owner of the property.</param>
|
|
||||||
/// <param name="e">Provides information about the updated property.</param>
|
|
||||||
private static void ContextMenuPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
TaskbarIcon owner = (TaskbarIcon) d;
|
|
||||||
owner.OnContextMenuPropertyChanged(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles changes of the <see cref="FrameworkElement.ContextMenuProperty"/> dependency property. As
|
|
||||||
/// WPF internally uses the dependency property system and bypasses the
|
|
||||||
/// <see cref="ContextMenu"/> property wrapper, updates of the property's value
|
|
||||||
/// should be handled here.
|
|
||||||
/// </summary
|
|
||||||
/// <param name="e">Provides information about the updated property.</param>
|
|
||||||
private void OnContextMenuPropertyChanged(DependencyPropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
//currently not needed
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//EVENTS
|
//EVENTS
|
||||||
|
|
||||||
@@ -1258,6 +1310,148 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
//ATTACHED EVENTS
|
||||||
|
|
||||||
|
#region PopupOpened
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// PopupOpened Attached Routed Event
|
||||||
|
/// </summary>
|
||||||
|
public static readonly RoutedEvent PopupOpenedEvent = EventManager.RegisterRoutedEvent("PopupOpened",
|
||||||
|
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a handler for the PopupOpened attached event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">UIElement or ContentElement that listens to the event</param>
|
||||||
|
/// <param name="handler">Event handler to be added</param>
|
||||||
|
public static void AddPopupOpenedHandler(DependencyObject element, RoutedEventHandler handler)
|
||||||
|
{
|
||||||
|
RoutedEventHelper.AddHandler(element, PopupOpenedEvent, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a handler for the PopupOpened attached event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">UIElement or ContentElement that listens to the event</param>
|
||||||
|
/// <param name="handler">Event handler to be removed</param>
|
||||||
|
public static void RemovePopupOpenedHandler(DependencyObject element, RoutedEventHandler handler)
|
||||||
|
{
|
||||||
|
RoutedEventHelper.RemoveHandler(element, PopupOpenedEvent, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A static helper method to raise the PopupOpened event on a target element.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target">UIElement or ContentElement on which to raise the event</param>
|
||||||
|
internal static RoutedEventArgs RaisePopupOpenedEvent(DependencyObject target)
|
||||||
|
{
|
||||||
|
if (target == null) return null;
|
||||||
|
|
||||||
|
RoutedEventArgs args = new RoutedEventArgs();
|
||||||
|
args.RoutedEvent = PopupOpenedEvent;
|
||||||
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region ToolTipOpened
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ToolTipOpened Attached Routed Event
|
||||||
|
/// </summary>
|
||||||
|
public static readonly RoutedEvent ToolTipOpenedEvent = EventManager.RegisterRoutedEvent("ToolTipOpened",
|
||||||
|
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a handler for the ToolTipOpened attached event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">UIElement or ContentElement that listens to the event</param>
|
||||||
|
/// <param name="handler">Event handler to be added</param>
|
||||||
|
public static void AddToolTipOpenedHandler(DependencyObject element, RoutedEventHandler handler)
|
||||||
|
{
|
||||||
|
RoutedEventHelper.AddHandler(element, ToolTipOpenedEvent, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a handler for the ToolTipOpened attached event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">UIElement or ContentElement that listens to the event</param>
|
||||||
|
/// <param name="handler">Event handler to be removed</param>
|
||||||
|
public static void RemoveToolTipOpenedHandler(DependencyObject element, RoutedEventHandler handler)
|
||||||
|
{
|
||||||
|
RoutedEventHelper.RemoveHandler(element, ToolTipOpenedEvent, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A static helper method to raise the ToolTipOpened event on a target element.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target">UIElement or ContentElement on which to raise the event</param>
|
||||||
|
internal static RoutedEventArgs RaiseToolTipOpenedEvent(DependencyObject target)
|
||||||
|
{
|
||||||
|
if (target == null) return null;
|
||||||
|
|
||||||
|
RoutedEventArgs args = new RoutedEventArgs();
|
||||||
|
args.RoutedEvent = ToolTipOpenedEvent;
|
||||||
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ToolTipClose
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ToolTipClose Attached Routed Event
|
||||||
|
/// </summary>
|
||||||
|
public static readonly RoutedEvent ToolTipCloseEvent = EventManager.RegisterRoutedEvent("ToolTipClose",
|
||||||
|
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a handler for the ToolTipClose attached event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">UIElement or ContentElement that listens to the event</param>
|
||||||
|
/// <param name="handler">Event handler to be added</param>
|
||||||
|
public static void AddToolTipCloseHandler(DependencyObject element, RoutedEventHandler handler)
|
||||||
|
{
|
||||||
|
RoutedEventHelper.AddHandler(element, ToolTipCloseEvent, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a handler for the ToolTipClose attached event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">UIElement or ContentElement that listens to the event</param>
|
||||||
|
/// <param name="handler">Event handler to be removed</param>
|
||||||
|
public static void RemoveToolTipCloseHandler(DependencyObject element, RoutedEventHandler handler)
|
||||||
|
{
|
||||||
|
RoutedEventHelper.RemoveHandler(element, ToolTipCloseEvent, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A static helper method to raise the ToolTipClose event on a target element.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target">UIElement or ContentElement on which to raise the event</param>
|
||||||
|
internal static RoutedEventArgs RaiseToolTipCloseEvent(DependencyObject target)
|
||||||
|
{
|
||||||
|
if (target == null) return null;
|
||||||
|
|
||||||
|
RoutedEventArgs args = new RoutedEventArgs();
|
||||||
|
args.RoutedEvent = ToolTipCloseEvent;
|
||||||
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//BASE CLASS PROPERTY OVERRIDES
|
//BASE CLASS PROPERTY OVERRIDES
|
||||||
|
|
||||||
@@ -1269,10 +1463,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
//register change listener for the Visibility property
|
//register change listener for the Visibility property
|
||||||
PropertyMetadata md = new PropertyMetadata(Visibility.Visible, VisibilityPropertyChanged);
|
PropertyMetadata md = new PropertyMetadata(Visibility.Visible, VisibilityPropertyChanged);
|
||||||
VisibilityProperty.OverrideMetadata(typeof(TaskbarIcon), md);
|
VisibilityProperty.OverrideMetadata(typeof(TaskbarIcon), md);
|
||||||
|
|
||||||
//register change listener for the ContextMenu property
|
|
||||||
md = new FrameworkPropertyMetadata(new PropertyChangedCallback(ContextMenuPropertyChanged));
|
|
||||||
ContextMenuProperty.OverrideMetadata(typeof (TaskbarIcon), md);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,360 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Controls.Primitives;
|
|
||||||
using Hardcodet.Wpf.TaskbarNotification.Interop;
|
|
||||||
using Point=Hardcodet.Wpf.TaskbarNotification.Interop.Point;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Hardcodet.Wpf.TaskbarNotification
|
|
||||||
{
|
|
||||||
partial class TaskbarIcon
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// An action that is being invoked if the
|
|
||||||
/// <see cref="singleClickTimer"/> fires.
|
|
||||||
/// </summary>
|
|
||||||
private Action delayedTimerAction;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A timer that is used to differentiate between single
|
|
||||||
/// and double clicks.
|
|
||||||
/// </summary>
|
|
||||||
private readonly Timer singleClickTimer;
|
|
||||||
|
|
||||||
|
|
||||||
#region ToolTip
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Displays a custom tooltip, if available. This method is only
|
|
||||||
/// invoked for Windows Vista and above.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="visible">Whether to show or hide the tooltip.</param>
|
|
||||||
private void OnToolTipChange(bool visible)
|
|
||||||
{
|
|
||||||
//if we don't have a tooltip, there's nothing to do here...
|
|
||||||
if (CustomToolTip == null) return;
|
|
||||||
|
|
||||||
if (visible)
|
|
||||||
{
|
|
||||||
if (ContextMenu != null && ContextMenu.IsOpen ||
|
|
||||||
CustomPopup != null && CustomPopup.IsOpen)
|
|
||||||
{
|
|
||||||
//ignore if we have an open context menu or popup
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = RaisePreviewTaskbarIconToolTipOpenEvent();
|
|
||||||
if (args.Handled) return;
|
|
||||||
|
|
||||||
CustomToolTip.IsOpen = true;
|
|
||||||
RaiseTaskbarIconToolTipOpenEvent();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var args = RaisePreviewTaskbarIconToolTipCloseEvent();
|
|
||||||
if (args.Handled) return;
|
|
||||||
|
|
||||||
CustomToolTip.IsOpen = false;
|
|
||||||
RaiseTaskbarIconToolTipCloseEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a <see cref="ToolTip"/> control that either
|
|
||||||
/// wraps the currently set <see cref="TaskbarIconToolTip"/>
|
|
||||||
/// control or the <see cref="ToolTipText"/> string.<br/>
|
|
||||||
/// If <see cref="TaskbarIconToolTip"/> itself is already
|
|
||||||
/// a <see cref="ToolTip"/> instance, it will be used directly.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>We use a <see cref="ToolTip"/> rather than
|
|
||||||
/// <see cref="Popup"/> because there was no way to prevent a
|
|
||||||
/// popup from causing cyclic open/close commands if it was
|
|
||||||
/// placed under the mouse. ToolTip internally uses a Popup of
|
|
||||||
/// its own, but takes advance of Popup's internal <see cref="Popup.HitTestable"/>
|
|
||||||
/// property which prevents this issue.</remarks>
|
|
||||||
private void CreateCustomToolTip()
|
|
||||||
{
|
|
||||||
//check if the item itself is a tooltip
|
|
||||||
ToolTip tt = TaskbarIconToolTip as ToolTip;
|
|
||||||
|
|
||||||
if (tt == null && TaskbarIconToolTip != null)
|
|
||||||
{
|
|
||||||
//create an invisible tooltip that hosts the UIElement
|
|
||||||
tt = new ToolTip();
|
|
||||||
tt.Placement = PlacementMode.Mouse;
|
|
||||||
tt.PlacementTarget = this;
|
|
||||||
|
|
||||||
//the tooltip (and implicitly its context) explicitly gets
|
|
||||||
//the DataContext of this instance. If there is no DataContext,
|
|
||||||
//the TaskbarIcon sets itself
|
|
||||||
tt.DataContext = DataContext ?? this;
|
|
||||||
|
|
||||||
//make sure the tooltip is invisible
|
|
||||||
tt.HasDropShadow = false;
|
|
||||||
tt.BorderThickness = new Thickness(0);
|
|
||||||
tt.Background = System.Windows.Media.Brushes.Transparent;
|
|
||||||
|
|
||||||
//setting the
|
|
||||||
tt.StaysOpen = true;
|
|
||||||
|
|
||||||
tt.Content = TaskbarIconToolTip;
|
|
||||||
}
|
|
||||||
else if (tt == null && !String.IsNullOrEmpty(ToolTipText))
|
|
||||||
{
|
|
||||||
//create a simple tooltip for the string
|
|
||||||
tt = new ToolTip();
|
|
||||||
tt.Content = ToolTipText;
|
|
||||||
}
|
|
||||||
|
|
||||||
//store a reference to the used tooltip
|
|
||||||
CustomToolTip = tt;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets tooltip settings for the class depending on defined
|
|
||||||
/// dependency properties and OS support.
|
|
||||||
/// </summary>
|
|
||||||
private void WriteToolTipSettings()
|
|
||||||
{
|
|
||||||
const IconDataMembers flags = IconDataMembers.Tip;
|
|
||||||
iconData.ToolTipText = ToolTipText;
|
|
||||||
|
|
||||||
if (messageSink.Version == NotifyIconVersion.Vista)
|
|
||||||
{
|
|
||||||
//we need to set a tooltip text to get tooltip events from the
|
|
||||||
//taskbar icon
|
|
||||||
if (String.IsNullOrEmpty(iconData.ToolTipText) && CustomToolTip != null)
|
|
||||||
{
|
|
||||||
//if we have not tooltip text but a custom tooltip, we
|
|
||||||
//need to set a dummy value (we're displaying the ToolTip control, not the string)
|
|
||||||
iconData.ToolTipText = "ToolTip";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the tooltip text
|
|
||||||
Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Show / Hide Balloon Tip
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Displays a balloon tip with the specified title,
|
|
||||||
/// text, and icon in the taskbar for the specified time period.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="title">The title to display on the balloon tip.</param>
|
|
||||||
/// <param name="message">The text to display on the balloon tip.</param>
|
|
||||||
/// <param name="symbol">A symbol that indicates the severity.</param>
|
|
||||||
public void ShowBalloonTip(string title, string message, BalloonIcon symbol)
|
|
||||||
{
|
|
||||||
lock (this)
|
|
||||||
{
|
|
||||||
ShowBalloonTip(title, message, symbol.GetBalloonFlag(), IntPtr.Zero);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Displays a balloon tip with the specified title,
|
|
||||||
/// text, and a custom icon in the taskbar for the specified time period.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="title">The title to display on the balloon tip.</param>
|
|
||||||
/// <param name="message">The text to display on the balloon tip.</param>
|
|
||||||
/// <param name="customIcon">A custom icon.</param>
|
|
||||||
/// <exception cref="ArgumentNullException">If <paramref name="customIcon"/>
|
|
||||||
/// is a null reference.</exception>
|
|
||||||
public void ShowBalloonTip(string title, string message, Icon customIcon)
|
|
||||||
{
|
|
||||||
if (customIcon == null) throw new ArgumentNullException("customIcon");
|
|
||||||
|
|
||||||
lock (this)
|
|
||||||
{
|
|
||||||
ShowBalloonTip(title, message, BalloonFlags.User, customIcon.Handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invokes <see cref="WinApi.Shell_NotifyIcon"/> in order to display
|
|
||||||
/// a given balloon ToolTip.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="title">The title to display on the balloon tip.</param>
|
|
||||||
/// <param name="message">The text to display on the balloon tip.</param>
|
|
||||||
/// <param name="flags">Indicates what icon to use.</param>
|
|
||||||
/// <param name="balloonIconHandle">A handle to a custom icon, if any, or
|
|
||||||
/// <see cref="IntPtr.Zero"/>.</param>
|
|
||||||
private void ShowBalloonTip(string title, string message, BalloonFlags flags, IntPtr balloonIconHandle)
|
|
||||||
{
|
|
||||||
EnsureNotDisposed();
|
|
||||||
|
|
||||||
iconData.BalloonText = message;
|
|
||||||
iconData.BalloonTitle = title;
|
|
||||||
|
|
||||||
iconData.BalloonFlags = flags;
|
|
||||||
iconData.CustomBalloonIconHandle = balloonIconHandle;
|
|
||||||
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Hides a balloon ToolTip, if any is displayed.
|
|
||||||
/// </summary>
|
|
||||||
public void HideBalloonTip()
|
|
||||||
{
|
|
||||||
EnsureNotDisposed();
|
|
||||||
|
|
||||||
//reset balloon by just setting the info to an empty string
|
|
||||||
iconData.BalloonText = iconData.BalloonTitle = String.Empty;
|
|
||||||
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Single Click Timer event
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Performs a delayed action if the user requested an action
|
|
||||||
/// based on a single click of the left mouse.<br/>
|
|
||||||
/// This method is invoked by the <see cref="singleClickTimer"/>.
|
|
||||||
/// </summary>
|
|
||||||
private void DoSingleClickAction(object state)
|
|
||||||
{
|
|
||||||
if (IsDisposed) return;
|
|
||||||
|
|
||||||
Console.Out.WriteLine("TIMER EVENT");
|
|
||||||
|
|
||||||
//run action
|
|
||||||
Action action = delayedTimerAction;
|
|
||||||
if (action != null)
|
|
||||||
{
|
|
||||||
//cleanup action
|
|
||||||
delayedTimerAction = null;
|
|
||||||
|
|
||||||
//switch to UI thread
|
|
||||||
Application.Current.Dispatcher.Invoke(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Create Popup
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a <see cref="ToolTip"/> control that either
|
|
||||||
/// wraps the currently set <see cref="TaskbarIconToolTip"/>
|
|
||||||
/// control or the <see cref="ToolTipText"/> string.<br/>
|
|
||||||
/// If <see cref="TaskbarIconToolTip"/> itself is already
|
|
||||||
/// a <see cref="ToolTip"/> instance, it will be used directly.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>We use a <see cref="ToolTip"/> rather than
|
|
||||||
/// <see cref="Popup"/> because there was no way to prevent a
|
|
||||||
/// popup from causing cyclic open/close commands if it was
|
|
||||||
/// placed under the mouse. ToolTip internally uses a Popup of
|
|
||||||
/// its own, but takes advance of Popup's internal <see cref="Popup.HitTestable"/>
|
|
||||||
/// property which prevents this issue.</remarks>
|
|
||||||
private void CreatePopup()
|
|
||||||
{
|
|
||||||
//no popup is available
|
|
||||||
if (TaskbarIconPopup == null) return;
|
|
||||||
|
|
||||||
//check if the item itself is a popup
|
|
||||||
Popup popup = TaskbarIconPopup as Popup;
|
|
||||||
|
|
||||||
if (popup == null)
|
|
||||||
{
|
|
||||||
//create an invisible popup that hosts the UIElement
|
|
||||||
popup = new Popup();
|
|
||||||
popup.AllowsTransparency = true;
|
|
||||||
popup.PopupAnimation = PopupAnimation.Fade;
|
|
||||||
|
|
||||||
//the tooltip (and implicitly its context) explicitly gets
|
|
||||||
//the DataContext of this instance. If there is no DataContext,
|
|
||||||
//the TaskbarIcon assigns itself
|
|
||||||
popup.DataContext = DataContext ?? this;
|
|
||||||
|
|
||||||
Popup.CreateRootPopup(popup, TaskbarIconPopup);
|
|
||||||
|
|
||||||
popup.PlacementTarget = this;
|
|
||||||
popup.Placement = PlacementMode.AbsolutePoint;
|
|
||||||
popup.StaysOpen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//store a reference to the used tooltip
|
|
||||||
CustomPopup = popup;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Show Tray Popup / Context Menu
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Displays the <see cref="TaskbarIconPopup"/> control if
|
|
||||||
/// it was set.
|
|
||||||
/// </summary>
|
|
||||||
private void ShowTrayPopup(Point cursorPosition)
|
|
||||||
{
|
|
||||||
if (IsDisposed) return;
|
|
||||||
|
|
||||||
//raise preview event no matter whether popup is currently set
|
|
||||||
//or not (enables client to set it on demand)
|
|
||||||
var args = RaisePreviewTaskbarIconPopupOpenEvent();
|
|
||||||
if (args.Handled) return;
|
|
||||||
|
|
||||||
if (TaskbarIconPopup != null)
|
|
||||||
{
|
|
||||||
//use absolute position, but place the popup centered above the icon
|
|
||||||
CustomPopup.Placement = PlacementMode.AbsolutePoint;
|
|
||||||
CustomPopup.HorizontalOffset = cursorPosition.X; //+ TaskbarIconPopup.ActualWidth/2;
|
|
||||||
CustomPopup.VerticalOffset = cursorPosition.Y;
|
|
||||||
|
|
||||||
//open popup
|
|
||||||
CustomPopup.IsOpen = true;
|
|
||||||
|
|
||||||
//activate the message window to track deactivation - otherwise, the context menu
|
|
||||||
//does not close if the user clicks somewhere else
|
|
||||||
WinApi.SetForegroundWindow(messageSink.MessageWindowHandle);
|
|
||||||
|
|
||||||
//bubble event
|
|
||||||
RaiseTaskbarIconPopupOpenEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Displays the <see cref="ContextMenu"/> if
|
|
||||||
/// it was set.
|
|
||||||
/// </summary>
|
|
||||||
private void ShowContextMenu(Point cursorPosition)
|
|
||||||
{
|
|
||||||
if (IsDisposed) return;
|
|
||||||
|
|
||||||
//raise preview event no matter whether context menu is currently set
|
|
||||||
//or not (enables client to set it on demand)
|
|
||||||
var args = RaisePreviewTaskbarIconContextMenuOpenEvent();
|
|
||||||
if (args.Handled) return;
|
|
||||||
|
|
||||||
if (ContextMenu != null)
|
|
||||||
{
|
|
||||||
//use absolute position
|
|
||||||
ContextMenu.Placement = PlacementMode.AbsolutePoint;
|
|
||||||
ContextMenu.HorizontalOffset = cursorPosition.X;
|
|
||||||
ContextMenu.VerticalOffset = cursorPosition.Y;
|
|
||||||
ContextMenu.IsOpen = true;
|
|
||||||
|
|
||||||
//activate the message window to track deactivation - otherwise, the context menu
|
|
||||||
//does not close if the user clicks somewhere else
|
|
||||||
WinApi.SetForegroundWindow(messageSink.MessageWindowHandle);
|
|
||||||
|
|
||||||
//bubble event
|
|
||||||
RaiseTaskbarIconContextMenuOpenEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Drawing;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using Hardcodet.Wpf.TaskbarNotification.Interop;
|
using Hardcodet.Wpf.TaskbarNotification.Interop;
|
||||||
using Point=Hardcodet.Wpf.TaskbarNotification.Interop.Point;
|
using Point=Hardcodet.Wpf.TaskbarNotification.Interop.Point;
|
||||||
|
|
||||||
|
|
||||||
namespace Hardcodet.Wpf.TaskbarNotification
|
namespace Hardcodet.Wpf.TaskbarNotification
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -30,11 +27,22 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly WindowMessageSink messageSink;
|
private readonly WindowMessageSink messageSink;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An action that is being invoked if the
|
||||||
|
/// <see cref="singleClickTimer"/> fires.
|
||||||
|
/// </summary>
|
||||||
|
private Action delayedTimerAction;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A timer that is used to differentiate between single
|
||||||
|
/// and double clicks.
|
||||||
|
/// </summary>
|
||||||
|
private readonly Timer singleClickTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates whether the taskbar icon has been created or not.
|
/// Indicates whether the taskbar icon has been created or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsTaskbarIconCreated { get; set; }
|
public bool IsTaskbarIconCreated { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates whether custom tooltips are supported, which depends
|
/// Indicates whether custom tooltips are supported, which depends
|
||||||
@@ -46,7 +54,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
get { return messageSink.Version == NotifyIconVersion.Vista; }
|
get { return messageSink.Version == NotifyIconVersion.Vista; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Construction
|
#region Construction
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -55,16 +62,10 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TaskbarIcon()
|
public TaskbarIcon()
|
||||||
{
|
{
|
||||||
//do nothing if in design mode
|
//using dummy sink in design mode
|
||||||
if (Util.IsDesignMode)
|
messageSink = Util.IsDesignMode
|
||||||
{
|
? WindowMessageSink.CreateEmpty()
|
||||||
messageSink = WindowMessageSink.CreateEmpty();
|
: new WindowMessageSink(NotifyIconVersion.Win95);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//create message sink that receives window messages
|
|
||||||
messageSink = new WindowMessageSink(NotifyIconVersion.Win95);
|
|
||||||
}
|
|
||||||
|
|
||||||
//init icon data structure
|
//init icon data structure
|
||||||
iconData = NotifyIconData.CreateDefault(messageSink.MessageWindowHandle);
|
iconData = NotifyIconData.CreateDefault(messageSink.MessageWindowHandle);
|
||||||
@@ -87,8 +88,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Process Incoming Mouse Events
|
||||||
#region Handle Mouse Events
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes mouse events, which are bubbled
|
/// Processes mouse events, which are bubbled
|
||||||
@@ -101,7 +101,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (IsDisposed) return;
|
if (IsDisposed) return;
|
||||||
|
|
||||||
switch(me)
|
switch (me)
|
||||||
{
|
{
|
||||||
case MouseEvent.MouseMove:
|
case MouseEvent.MouseMove:
|
||||||
RaiseTaskbarIconMouseMoveEvent();
|
RaiseTaskbarIconMouseMoveEvent();
|
||||||
@@ -136,7 +136,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me);
|
throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,6 +177,252 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ToolTips
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a custom tooltip, if available. This method is only
|
||||||
|
/// invoked for Windows Vista and above.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="visible">Whether to show or hide the tooltip.</param>
|
||||||
|
private void OnToolTipChange(bool visible)
|
||||||
|
{
|
||||||
|
//if we don't have a tooltip, there's nothing to do here...
|
||||||
|
if (CustomToolTip == null) return;
|
||||||
|
|
||||||
|
if (visible)
|
||||||
|
{
|
||||||
|
if (ContextMenu != null && ContextMenu.IsOpen ||
|
||||||
|
CustomPopup != null && CustomPopup.IsOpen)
|
||||||
|
{
|
||||||
|
//ignore if we have an open context menu or popup
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var args = RaisePreviewTaskbarIconToolTipOpenEvent();
|
||||||
|
if (args.Handled) return;
|
||||||
|
|
||||||
|
CustomToolTip.IsOpen = true;
|
||||||
|
|
||||||
|
//raise attached event first
|
||||||
|
if (TaskbarIconToolTip != null) RaiseToolTipOpenedEvent(TaskbarIconToolTip);
|
||||||
|
|
||||||
|
//bubble routed event
|
||||||
|
RaiseTaskbarIconToolTipOpenEvent();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var args = RaisePreviewTaskbarIconToolTipCloseEvent();
|
||||||
|
if (args.Handled) return;
|
||||||
|
|
||||||
|
//raise attached event first
|
||||||
|
if (TaskbarIconToolTip != null) RaiseToolTipCloseEvent(TaskbarIconToolTip);
|
||||||
|
|
||||||
|
//CustomToolTip.IsOpen = false;
|
||||||
|
RaiseTaskbarIconToolTipCloseEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="ToolTip"/> control that either
|
||||||
|
/// wraps the currently set <see cref="TaskbarIconToolTip"/>
|
||||||
|
/// control or the <see cref="ToolTipText"/> string.<br/>
|
||||||
|
/// If <see cref="TaskbarIconToolTip"/> itself is already
|
||||||
|
/// a <see cref="ToolTip"/> instance, it will be used directly.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>We use a <see cref="ToolTip"/> rather than
|
||||||
|
/// <see cref="Popup"/> because there was no way to prevent a
|
||||||
|
/// popup from causing cyclic open/close commands if it was
|
||||||
|
/// placed under the mouse. ToolTip internally uses a Popup of
|
||||||
|
/// its own, but takes advance of Popup's internal <see cref="Popup.HitTestable"/>
|
||||||
|
/// property which prevents this issue.</remarks>
|
||||||
|
private void CreateCustomToolTip()
|
||||||
|
{
|
||||||
|
//check if the item itself is a tooltip
|
||||||
|
ToolTip tt = TaskbarIconToolTip as ToolTip;
|
||||||
|
|
||||||
|
if (tt == null && TaskbarIconToolTip != null)
|
||||||
|
{
|
||||||
|
//create an invisible tooltip that hosts the UIElement
|
||||||
|
tt = new ToolTip();
|
||||||
|
tt.Placement = PlacementMode.Mouse;
|
||||||
|
tt.PlacementTarget = this;
|
||||||
|
|
||||||
|
//the tooltip (and implicitly its context) explicitly gets
|
||||||
|
//the DataContext of this instance. If there is no DataContext,
|
||||||
|
//the TaskbarIcon sets itself
|
||||||
|
tt.DataContext = DataContext ?? this;
|
||||||
|
|
||||||
|
//make sure the tooltip is invisible
|
||||||
|
tt.HasDropShadow = false;
|
||||||
|
tt.BorderThickness = new Thickness(0);
|
||||||
|
tt.Background = System.Windows.Media.Brushes.Transparent;
|
||||||
|
|
||||||
|
//setting the
|
||||||
|
tt.StaysOpen = true;
|
||||||
|
|
||||||
|
tt.Content = TaskbarIconToolTip;
|
||||||
|
}
|
||||||
|
else if (tt == null && !String.IsNullOrEmpty(ToolTipText))
|
||||||
|
{
|
||||||
|
//create a simple tooltip for the string
|
||||||
|
tt = new ToolTip();
|
||||||
|
tt.Content = ToolTipText;
|
||||||
|
}
|
||||||
|
|
||||||
|
//store a reference to the used tooltip
|
||||||
|
CustomToolTip = tt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets tooltip settings for the class depending on defined
|
||||||
|
/// dependency properties and OS support.
|
||||||
|
/// </summary>
|
||||||
|
private void WriteToolTipSettings()
|
||||||
|
{
|
||||||
|
const IconDataMembers flags = IconDataMembers.Tip;
|
||||||
|
iconData.ToolTipText = ToolTipText;
|
||||||
|
|
||||||
|
if (messageSink.Version == NotifyIconVersion.Vista)
|
||||||
|
{
|
||||||
|
//we need to set a tooltip text to get tooltip events from the
|
||||||
|
//taskbar icon
|
||||||
|
if (String.IsNullOrEmpty(iconData.ToolTipText) && CustomToolTip != null)
|
||||||
|
{
|
||||||
|
//if we have not tooltip text but a custom tooltip, we
|
||||||
|
//need to set a dummy value (we're displaying the ToolTip control, not the string)
|
||||||
|
iconData.ToolTipText = "ToolTip";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the tooltip text
|
||||||
|
Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Custom Popup
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="ToolTip"/> control that either
|
||||||
|
/// wraps the currently set <see cref="TaskbarIconToolTip"/>
|
||||||
|
/// control or the <see cref="ToolTipText"/> string.<br/>
|
||||||
|
/// If <see cref="TaskbarIconToolTip"/> itself is already
|
||||||
|
/// a <see cref="ToolTip"/> instance, it will be used directly.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>We use a <see cref="ToolTip"/> rather than
|
||||||
|
/// <see cref="Popup"/> because there was no way to prevent a
|
||||||
|
/// popup from causing cyclic open/close commands if it was
|
||||||
|
/// placed under the mouse. ToolTip internally uses a Popup of
|
||||||
|
/// its own, but takes advance of Popup's internal <see cref="Popup.HitTestable"/>
|
||||||
|
/// property which prevents this issue.</remarks>
|
||||||
|
private void CreatePopup()
|
||||||
|
{
|
||||||
|
//no popup is available
|
||||||
|
if (TaskbarIconPopup == null) return;
|
||||||
|
|
||||||
|
//check if the item itself is a popup
|
||||||
|
Popup popup = TaskbarIconPopup as Popup;
|
||||||
|
|
||||||
|
if (popup == null)
|
||||||
|
{
|
||||||
|
//create an invisible popup that hosts the UIElement
|
||||||
|
popup = new Popup();
|
||||||
|
popup.AllowsTransparency = true;
|
||||||
|
popup.PopupAnimation = PopupAnimation.Fade;
|
||||||
|
|
||||||
|
//the tooltip (and implicitly its context) explicitly gets
|
||||||
|
//the DataContext of this instance. If there is no DataContext,
|
||||||
|
//the TaskbarIcon assigns itself
|
||||||
|
popup.DataContext = DataContext ?? this;
|
||||||
|
|
||||||
|
Popup.CreateRootPopup(popup, TaskbarIconPopup);
|
||||||
|
|
||||||
|
popup.PlacementTarget = this;
|
||||||
|
popup.Placement = PlacementMode.AbsolutePoint;
|
||||||
|
popup.StaysOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//store a reference to the used tooltip
|
||||||
|
CustomPopup = popup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays the <see cref="TaskbarIconPopup"/> control if
|
||||||
|
/// it was set.
|
||||||
|
/// </summary>
|
||||||
|
private void ShowTrayPopup(Point cursorPosition)
|
||||||
|
{
|
||||||
|
if (IsDisposed) return;
|
||||||
|
|
||||||
|
//raise preview event no matter whether popup is currently set
|
||||||
|
//or not (enables client to set it on demand)
|
||||||
|
var args = RaisePreviewTaskbarIconPopupOpenEvent();
|
||||||
|
if (args.Handled) return;
|
||||||
|
|
||||||
|
if (TaskbarIconPopup != null)
|
||||||
|
{
|
||||||
|
//use absolute position, but place the popup centered above the icon
|
||||||
|
CustomPopup.Placement = PlacementMode.AbsolutePoint;
|
||||||
|
CustomPopup.HorizontalOffset = cursorPosition.X; //+ TaskbarIconPopup.ActualWidth/2;
|
||||||
|
CustomPopup.VerticalOffset = cursorPosition.Y;
|
||||||
|
|
||||||
|
//open popup
|
||||||
|
CustomPopup.IsOpen = true;
|
||||||
|
|
||||||
|
//activate the message window to track deactivation - otherwise, the context menu
|
||||||
|
//does not close if the user clicks somewhere else
|
||||||
|
WinApi.SetForegroundWindow(messageSink.MessageWindowHandle);
|
||||||
|
|
||||||
|
//raise attached event - item should never be null unless developers
|
||||||
|
//changed the CustomPopup directly...
|
||||||
|
if (TaskbarIconPopup != null) RaisePopupOpenedEvent(TaskbarIconPopup);
|
||||||
|
|
||||||
|
//bubble routed event
|
||||||
|
RaiseTaskbarIconPopupOpenEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Context Menu
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays the <see cref="ContextMenu"/> if
|
||||||
|
/// it was set.
|
||||||
|
/// </summary>
|
||||||
|
private void ShowContextMenu(Point cursorPosition)
|
||||||
|
{
|
||||||
|
if (IsDisposed) return;
|
||||||
|
|
||||||
|
//raise preview event no matter whether context menu is currently set
|
||||||
|
//or not (enables client to set it on demand)
|
||||||
|
var args = RaisePreviewTaskbarIconContextMenuOpenEvent();
|
||||||
|
if (args.Handled) return;
|
||||||
|
|
||||||
|
if (ContextMenu != null)
|
||||||
|
{
|
||||||
|
//use absolute position
|
||||||
|
ContextMenu.Placement = PlacementMode.AbsolutePoint;
|
||||||
|
ContextMenu.HorizontalOffset = cursorPosition.X;
|
||||||
|
ContextMenu.VerticalOffset = cursorPosition.Y;
|
||||||
|
ContextMenu.IsOpen = true;
|
||||||
|
|
||||||
|
//activate the message window to track deactivation - otherwise, the context menu
|
||||||
|
//does not close if the user clicks somewhere else
|
||||||
|
WinApi.SetForegroundWindow(messageSink.MessageWindowHandle);
|
||||||
|
|
||||||
|
//bubble event
|
||||||
|
RaiseTaskbarIconContextMenuOpenEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Balloon Tips
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Bubbles events if a balloon ToolTip was displayed
|
/// Bubbles events if a balloon ToolTip was displayed
|
||||||
@@ -197,28 +442,122 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a balloon tip with the specified title,
|
||||||
|
/// text, and icon in the taskbar for the specified time period.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">The title to display on the balloon tip.</param>
|
||||||
|
/// <param name="message">The text to display on the balloon tip.</param>
|
||||||
|
/// <param name="symbol">A symbol that indicates the severity.</param>
|
||||||
|
public void ShowBalloonTip(string title, string message, BalloonIcon symbol)
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
ShowBalloonTip(title, message, symbol.GetBalloonFlag(), IntPtr.Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a balloon tip with the specified title,
|
||||||
|
/// text, and a custom icon in the taskbar for the specified time period.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">The title to display on the balloon tip.</param>
|
||||||
|
/// <param name="message">The text to display on the balloon tip.</param>
|
||||||
|
/// <param name="customIcon">A custom icon.</param>
|
||||||
|
/// <exception cref="ArgumentNullException">If <paramref name="customIcon"/>
|
||||||
|
/// is a null reference.</exception>
|
||||||
|
public void ShowBalloonTip(string title, string message, Icon customIcon)
|
||||||
|
{
|
||||||
|
if (customIcon == null) throw new ArgumentNullException("customIcon");
|
||||||
|
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
ShowBalloonTip(title, message, BalloonFlags.User, customIcon.Handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes <see cref="WinApi.Shell_NotifyIcon"/> in order to display
|
||||||
|
/// a given balloon ToolTip.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">The title to display on the balloon tip.</param>
|
||||||
|
/// <param name="message">The text to display on the balloon tip.</param>
|
||||||
|
/// <param name="flags">Indicates what icon to use.</param>
|
||||||
|
/// <param name="balloonIconHandle">A handle to a custom icon, if any, or
|
||||||
|
/// <see cref="IntPtr.Zero"/>.</param>
|
||||||
|
private void ShowBalloonTip(string title, string message, BalloonFlags flags, IntPtr balloonIconHandle)
|
||||||
|
{
|
||||||
|
EnsureNotDisposed();
|
||||||
|
|
||||||
|
iconData.BalloonText = message;
|
||||||
|
iconData.BalloonTitle = title;
|
||||||
|
|
||||||
|
iconData.BalloonFlags = flags;
|
||||||
|
iconData.CustomBalloonIconHandle = balloonIconHandle;
|
||||||
|
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hides a balloon ToolTip, if any is displayed.
|
||||||
|
/// </summary>
|
||||||
|
public void HideBalloonTip()
|
||||||
|
{
|
||||||
|
EnsureNotDisposed();
|
||||||
|
|
||||||
|
//reset balloon by just setting the info to an empty string
|
||||||
|
iconData.BalloonText = iconData.BalloonTitle = String.Empty;
|
||||||
|
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Single Click Timer event
|
||||||
|
|
||||||
#region SetVersion
|
/// <summary>
|
||||||
|
/// Performs a delayed action if the user requested an action
|
||||||
|
/// based on a single click of the left mouse.<br/>
|
||||||
|
/// This method is invoked by the <see cref="singleClickTimer"/>.
|
||||||
|
/// </summary>
|
||||||
|
private void DoSingleClickAction(object state)
|
||||||
|
{
|
||||||
|
if (IsDisposed) return;
|
||||||
|
|
||||||
|
//run action
|
||||||
|
Action action = delayedTimerAction;
|
||||||
|
if (action != null)
|
||||||
|
{
|
||||||
|
//cleanup action
|
||||||
|
delayedTimerAction = null;
|
||||||
|
|
||||||
|
//switch to UI thread
|
||||||
|
Application.Current.Dispatcher.Invoke(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Set Version (API)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the version flag for the <see cref="iconData"/>.
|
/// Sets the version flag for the <see cref="iconData"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void SetVersion()
|
private void SetVersion()
|
||||||
{
|
{
|
||||||
iconData.VersionOrTimeout = (uint)NotifyIconVersion.Vista;
|
iconData.VersionOrTimeout = (uint) NotifyIconVersion.Vista;
|
||||||
bool status = WinApi.Shell_NotifyIcon(NotifyCommand.SetVersion, ref iconData);
|
bool status = WinApi.Shell_NotifyIcon(NotifyCommand.SetVersion, ref iconData);
|
||||||
|
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
iconData.VersionOrTimeout = (uint)NotifyIconVersion.Win2000;
|
iconData.VersionOrTimeout = (uint) NotifyIconVersion.Win2000;
|
||||||
status = Util.WriteIconData(ref iconData, NotifyCommand.SetVersion);
|
status = Util.WriteIconData(ref iconData, NotifyCommand.SetVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
iconData.VersionOrTimeout = (uint)NotifyIconVersion.Win95;
|
iconData.VersionOrTimeout = (uint) NotifyIconVersion.Win95;
|
||||||
status = Util.WriteIconData(ref iconData, NotifyCommand.SetVersion);
|
status = Util.WriteIconData(ref iconData, NotifyCommand.SetVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +569,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Create / Remove Taskbar Icon
|
#region Create / Remove Taskbar Icon
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -292,7 +630,6 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Dispose / Exit
|
#region Dispose / Exit
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -311,7 +648,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (IsDisposed) throw new ObjectDisposedException(Name ?? GetType().FullName);
|
if (IsDisposed) throw new ObjectDisposedException(Name ?? GetType().FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes the class if the application exits.
|
/// Disposes the class if the application exits.
|
||||||
@@ -320,7 +657,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This destructor will run only if the <see cref="Dispose()"/>
|
/// This destructor will run only if the <see cref="Dispose()"/>
|
||||||
@@ -372,7 +709,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <remarks>Check the <see cref="IsDisposed"/> property to determine whether
|
/// <remarks>Check the <see cref="IsDisposed"/> property to determine whether
|
||||||
/// the method has already been called.</remarks>
|
/// the method has already been called.</remarks>
|
||||||
private void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
//don't do anything if the component is already disposed
|
//don't do anything if the component is already disposed
|
||||||
if (IsDisposed || !disposing) return;
|
if (IsDisposed || !disposing) return;
|
||||||
|
|
||||||
@@ -389,10 +726,11 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
//dispose message sink
|
//dispose message sink
|
||||||
messageSink.Dispose();
|
messageSink.Dispose();
|
||||||
|
|
||||||
|
//remove icon
|
||||||
RemoveTaskbarIcon();
|
RemoveTaskbarIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,22 @@
|
|||||||
x:Class="Sample_Project.FancyPopup"
|
x:Class="Sample_Project.FancyPopup"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||||
Height="215"
|
Height="215"
|
||||||
Width="300" x:Name="me">
|
Width="300" x:Name="me">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<Storyboard x:Key="RotateIcon">
|
||||||
|
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
|
||||||
|
<SplineDoubleKeyFrame KeySpline="0,0.284,0.39,1" KeyTime="00:00:01.4000000" Value="360"/>
|
||||||
|
</DoubleAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
</UserControl.Resources>
|
||||||
|
<UserControl.Triggers>
|
||||||
|
<EventTrigger RoutedEvent="tb:TaskbarIcon.PopupOpened">
|
||||||
|
<BeginStoryboard Storyboard="{StaticResource RotateIcon}" x:Name="RotateIcon_BeginStoryboard"/>
|
||||||
|
</EventTrigger>
|
||||||
|
</UserControl.Triggers>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Border
|
<Border
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
@@ -36,7 +50,16 @@
|
|||||||
Width="72"
|
Width="72"
|
||||||
Height="72"
|
Height="72"
|
||||||
Source="Images\preferences.png"
|
Source="Images\preferences.png"
|
||||||
Stretch="Fill" />
|
Stretch="Fill" x:Name="image" RenderTransformOrigin="0.5,0.5" >
|
||||||
|
<Image.RenderTransform>
|
||||||
|
<TransformGroup>
|
||||||
|
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
||||||
|
<SkewTransform AngleX="0" AngleY="0"/>
|
||||||
|
<RotateTransform Angle="0"/>
|
||||||
|
<TranslateTransform X="0" Y="0"/>
|
||||||
|
</TransformGroup>
|
||||||
|
</Image.RenderTransform>
|
||||||
|
</Image>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Margin="107,10,20,0"
|
Margin="107,10,20,0"
|
||||||
TextWrapping="Wrap"
|
TextWrapping="Wrap"
|
||||||
|
|||||||
@@ -3,12 +3,42 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:tb="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification"
|
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
x:Class="Sample_Project.FancyToolTip"
|
x:Class="Sample_Project.FancyToolTip"
|
||||||
x:Name="me"
|
x:Name="me"
|
||||||
Width="285"
|
Width="285"
|
||||||
Height="108">
|
Height="108">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<Storyboard x:Key="FadeIn">
|
||||||
|
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.Opacity)">
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.25"/>
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
|
||||||
|
</DoubleAnimationUsingKeyFrames>
|
||||||
|
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.Opacity)">
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.6"/>
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
|
||||||
|
</DoubleAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
<Storyboard x:Key="FadeOut">
|
||||||
|
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.Opacity)">
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0.25"/>
|
||||||
|
</DoubleAnimationUsingKeyFrames>
|
||||||
|
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.Opacity)">
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
|
||||||
|
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0.6"/>
|
||||||
|
</DoubleAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
</UserControl.Resources>
|
||||||
|
<UserControl.Triggers>
|
||||||
|
<EventTrigger RoutedEvent="tb:TaskbarIcon.ToolTipOpened">
|
||||||
|
<BeginStoryboard Storyboard="{StaticResource FadeIn}" x:Name="FadeIn_BeginStoryboard"/>
|
||||||
|
</EventTrigger>
|
||||||
|
<EventTrigger RoutedEvent="tb:TaskbarIcon.ToolTipClose">
|
||||||
|
<BeginStoryboard Storyboard="{StaticResource FadeOut}" x:Name="FadeOut_BeginStoryboard"/>
|
||||||
|
</EventTrigger>
|
||||||
|
</UserControl.Triggers>
|
||||||
|
|
||||||
<Grid
|
<Grid
|
||||||
x:Name="LayoutRoot">
|
x:Name="LayoutRoot">
|
||||||
@@ -19,7 +49,7 @@
|
|||||||
Height="Auto"
|
Height="Auto"
|
||||||
CornerRadius="6,6,6,6"
|
CornerRadius="6,6,6,6"
|
||||||
BorderThickness="3,3,3,3"
|
BorderThickness="3,3,3,3"
|
||||||
Margin="0,0,5,5">
|
Margin="0,0,5,5" x:Name="border">
|
||||||
<Border.Effect>
|
<Border.Effect>
|
||||||
<DropShadowEffect
|
<DropShadowEffect
|
||||||
Color="#FF7A7A7A" />
|
Color="#FF7A7A7A" />
|
||||||
@@ -44,7 +74,16 @@
|
|||||||
Source="Images\Info.png"
|
Source="Images\Info.png"
|
||||||
Stretch="Fill"
|
Stretch="Fill"
|
||||||
VerticalAlignment="Top"
|
VerticalAlignment="Top"
|
||||||
RenderTransformOrigin="0.792,0.486" />
|
RenderTransformOrigin="0.792,0.486" x:Name="image" >
|
||||||
|
<Image.RenderTransform>
|
||||||
|
<TransformGroup>
|
||||||
|
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
||||||
|
<SkewTransform AngleX="0" AngleY="0"/>
|
||||||
|
<RotateTransform Angle="0"/>
|
||||||
|
<TranslateTransform X="0" Y="0"/>
|
||||||
|
</TransformGroup>
|
||||||
|
</Image.RenderTransform>
|
||||||
|
</Image>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Margin="82,10,20,0"
|
Margin="82,10,20,0"
|
||||||
TextWrapping="Wrap"
|
TextWrapping="Wrap"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using Hardcodet.Wpf.TaskbarNotification;
|
||||||
|
|
||||||
namespace Sample_Project
|
namespace Sample_Project
|
||||||
{
|
{
|
||||||
@@ -27,7 +28,7 @@ namespace Sample_Project
|
|||||||
DependencyProperty.Register("InfoText",
|
DependencyProperty.Register("InfoText",
|
||||||
typeof (string),
|
typeof (string),
|
||||||
typeof (FancyToolTip),
|
typeof (FancyToolTip),
|
||||||
new FrameworkPropertyMetadata("", InfoTextPropertyChanged));
|
new FrameworkPropertyMetadata(""));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A property wrapper for the <see cref="InfoTextProperty"/>
|
/// A property wrapper for the <see cref="InfoTextProperty"/>
|
||||||
@@ -40,34 +41,6 @@ namespace Sample_Project
|
|||||||
set { SetValue(InfoTextProperty, value); }
|
set { SetValue(InfoTextProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A static callback listener which is being invoked if the
|
|
||||||
/// <see cref="InfoTextProperty"/> dependency property has
|
|
||||||
/// been changed. Invokes the <see cref="OnInfoTextPropertyChanged"/>
|
|
||||||
/// instance method of the changed instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="d">The currently processed owner of the property.</param>
|
|
||||||
/// <param name="e">Provides information about the updated property.</param>
|
|
||||||
private static void InfoTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
FancyToolTip owner = (FancyToolTip) d;
|
|
||||||
owner.OnInfoTextPropertyChanged(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles changes of the <see cref="InfoTextProperty"/> dependency property. As
|
|
||||||
/// WPF internally uses the dependency property system and bypasses the
|
|
||||||
/// <see cref="InfoText"/> property wrapper, updates of the property's value
|
|
||||||
/// should be handled here.
|
|
||||||
/// </summary
|
|
||||||
/// <param name="e">Provides information about the updated property.</param>
|
|
||||||
private void OnInfoTextPropertyChanged(DependencyPropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
// string newValue = (string) e.NewValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -76,5 +49,6 @@ namespace Sample_Project
|
|||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,117 +25,25 @@
|
|||||||
TypeName="tb:PopupActivationMode" />
|
TypeName="tb:PopupActivationMode" />
|
||||||
</ObjectDataProvider.MethodParameters>
|
</ObjectDataProvider.MethodParameters>
|
||||||
</ObjectDataProvider>
|
</ObjectDataProvider>
|
||||||
|
<Storyboard x:Key="FadeToolTip"/>
|
||||||
|
|
||||||
<Storyboard
|
|
||||||
x:Key="OnTaskbarIconLeftMouseUp1">
|
|
||||||
<BooleanAnimationUsingKeyFrames
|
|
||||||
BeginTime="00:00:00"
|
|
||||||
Storyboard.TargetName="popup"
|
|
||||||
Storyboard.TargetProperty="(Popup.IsOpen)">
|
|
||||||
<DiscreteBooleanKeyFrame
|
|
||||||
KeyTime="00:00:00"
|
|
||||||
Value="True" />
|
|
||||||
<DiscreteBooleanKeyFrame
|
|
||||||
KeyTime="00:00:02"
|
|
||||||
Value="False" />
|
|
||||||
</BooleanAnimationUsingKeyFrames>
|
|
||||||
<DoubleAnimationUsingKeyFrames
|
|
||||||
BeginTime="00:00:00"
|
|
||||||
Storyboard.TargetName="ellipse"
|
|
||||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:00"
|
|
||||||
Value="0" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:01"
|
|
||||||
Value="74" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:01.5000000"
|
|
||||||
Value="26" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:02"
|
|
||||||
Value="0" />
|
|
||||||
</DoubleAnimationUsingKeyFrames>
|
|
||||||
<DoubleAnimationUsingKeyFrames
|
|
||||||
BeginTime="00:00:00"
|
|
||||||
Storyboard.TargetName="ellipse"
|
|
||||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:00"
|
|
||||||
Value="0" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:01"
|
|
||||||
Value="106" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:01.5000000"
|
|
||||||
Value="151" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:02"
|
|
||||||
Value="0" />
|
|
||||||
</DoubleAnimationUsingKeyFrames>
|
|
||||||
<DoubleAnimationUsingKeyFrames
|
|
||||||
BeginTime="00:00:00"
|
|
||||||
Storyboard.TargetName="popup"
|
|
||||||
Storyboard.TargetProperty="(UIElement.Opacity)">
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:00"
|
|
||||||
Value="0.1" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:02"
|
|
||||||
Value="1" />
|
|
||||||
</DoubleAnimationUsingKeyFrames>
|
|
||||||
<DoubleAnimationUsingKeyFrames
|
|
||||||
BeginTime="00:00:00"
|
|
||||||
Storyboard.TargetName="ellipse"
|
|
||||||
Storyboard.TargetProperty="(UIElement.Opacity)">
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:00"
|
|
||||||
Value="0.47" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:01"
|
|
||||||
Value="1" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:01.5000000"
|
|
||||||
Value="1" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:02"
|
|
||||||
Value="0.685" />
|
|
||||||
</DoubleAnimationUsingKeyFrames>
|
|
||||||
<DoubleAnimationUsingKeyFrames
|
|
||||||
BeginTime="00:00:00"
|
|
||||||
Storyboard.TargetName="border"
|
|
||||||
Storyboard.TargetProperty="(UIElement.Opacity)">
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:00"
|
|
||||||
Value="1" />
|
|
||||||
<SplineDoubleKeyFrame
|
|
||||||
KeyTime="00:00:01"
|
|
||||||
Value="0.515" />
|
|
||||||
</DoubleAnimationUsingKeyFrames>
|
|
||||||
</Storyboard>
|
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
<Window.Triggers>
|
<Window.Triggers>
|
||||||
<EventTrigger
|
<EventTrigger RoutedEvent="tb:TaskbarIcon.TaskbarIconToolTipOpen" SourceName="tb"/>
|
||||||
RoutedEvent="tb:TaskbarIcon.TaskbarIconLeftMouseUp"
|
</Window.Triggers>
|
||||||
SourceName="tb">
|
|
||||||
<BeginStoryboard
|
|
||||||
Storyboard="{StaticResource OnTaskbarIconLeftMouseUp1}" />
|
|
||||||
</EventTrigger>
|
|
||||||
</Window.Triggers>
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<tb:TaskbarIcon
|
<tb:TaskbarIcon
|
||||||
x:Name="tb"
|
x:Name="tb"
|
||||||
VerticalAlignment="Top"
|
VerticalAlignment="Top"
|
||||||
IconSource="{Binding Path=SelectedItem.Source, ElementName=iconList, Mode=Default}"
|
IconSource="{Binding Path=SelectedItem.Source, ElementName=iconList, Mode=Default}"
|
||||||
ContextMenu="{DynamicResource tbMenu}"
|
ContextMenu="{DynamicResource tbMenu}"
|
||||||
ToolTip="hello world"
|
|
||||||
ToolTipText="{Binding Path=Text, ElementName=txtToolTipText, Mode=Default}"
|
ToolTipText="{Binding Path=Text, ElementName=txtToolTipText, Mode=Default}"
|
||||||
Visibility="{Binding Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=iconVisibility, Mode=Default}"
|
Visibility="{Binding Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=iconVisibility, Mode=Default}"
|
||||||
MenuActivation="{Binding Path=SelectedItem, ElementName=lstMenuTrigger, Mode=Default}"
|
MenuActivation="{Binding Path=SelectedItem, ElementName=lstMenuTrigger, Mode=Default}"
|
||||||
PopupActivation="{Binding Path=SelectedItem, ElementName=lstPopupTrigger, Mode=Default}">
|
PopupActivation="{Binding Path=SelectedItem, ElementName=lstPopupTrigger, Mode=Default}">
|
||||||
|
|
||||||
<tb:TaskbarIcon.TaskbarIconPopup>
|
<tb:TaskbarIcon.TaskbarIconPopup>
|
||||||
|
<!-- the control will be put into a popup with an explicit DataContext -->
|
||||||
<local:FancyPopup />
|
<local:FancyPopup />
|
||||||
</tb:TaskbarIcon.TaskbarIconPopup>
|
</tb:TaskbarIcon.TaskbarIconPopup>
|
||||||
|
|
||||||
@@ -148,6 +56,13 @@
|
|||||||
|
|
||||||
</tb:TaskbarIcon>
|
</tb:TaskbarIcon>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- EVERYTHING BELOW IS JUST PLUMBING FOR THE SAMPLE -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
x:Name="btn"
|
x:Name="btn"
|
||||||
Click="OnClick"
|
Click="OnClick"
|
||||||
@@ -165,58 +80,6 @@
|
|||||||
VerticalAlignment="Top"
|
VerticalAlignment="Top"
|
||||||
Width="75"
|
Width="75"
|
||||||
Content="Button" />
|
Content="Button" />
|
||||||
<Popup
|
|
||||||
x:Name="popup"
|
|
||||||
Margin="-231,-276,231,0"
|
|
||||||
VerticalAlignment="Top"
|
|
||||||
Height="549"
|
|
||||||
d:IsHidden="True"
|
|
||||||
d:IsLocked="True">
|
|
||||||
<Grid
|
|
||||||
Width="180"
|
|
||||||
Height="227">
|
|
||||||
<Border
|
|
||||||
CornerRadius="10,10,10,10"
|
|
||||||
x:Name="border">
|
|
||||||
<Border.Background>
|
|
||||||
<LinearGradientBrush
|
|
||||||
EndPoint="0.5,1"
|
|
||||||
StartPoint="0.5,0">
|
|
||||||
<GradientStop
|
|
||||||
Color="#FFF4B569"
|
|
||||||
Offset="0" />
|
|
||||||
<GradientStop
|
|
||||||
Color="#FFFFFFFF"
|
|
||||||
Offset="1" />
|
|
||||||
</LinearGradientBrush>
|
|
||||||
</Border.Background>
|
|
||||||
</Border>
|
|
||||||
<Ellipse
|
|
||||||
Fill="#FFC13E3E"
|
|
||||||
Stroke="#FF000000"
|
|
||||||
VerticalAlignment="Top"
|
|
||||||
Height="58"
|
|
||||||
Margin="51,19,75,0"
|
|
||||||
x:Name="ellipse"
|
|
||||||
RenderTransformOrigin="0.5,0.5">
|
|
||||||
<Ellipse.RenderTransform>
|
|
||||||
<TransformGroup>
|
|
||||||
<ScaleTransform
|
|
||||||
ScaleX="1"
|
|
||||||
ScaleY="1" />
|
|
||||||
<SkewTransform
|
|
||||||
AngleX="0"
|
|
||||||
AngleY="0" />
|
|
||||||
<RotateTransform
|
|
||||||
Angle="0" />
|
|
||||||
<TranslateTransform
|
|
||||||
X="0"
|
|
||||||
Y="0" />
|
|
||||||
</TransformGroup>
|
|
||||||
</Ellipse.RenderTransform>
|
|
||||||
</Ellipse>
|
|
||||||
</Grid>
|
|
||||||
</Popup>
|
|
||||||
<CheckBox
|
<CheckBox
|
||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
Margin="8,116,0,0"
|
Margin="8,116,0,0"
|
||||||
@@ -410,7 +273,7 @@
|
|||||||
BorderBrush="#FF000000"
|
BorderBrush="#FF000000"
|
||||||
BorderThickness="2,2,2,2" />
|
BorderThickness="2,2,2,2" />
|
||||||
<ListBox
|
<ListBox
|
||||||
Margin="10,0,128,10"
|
Margin="10,0,95,10"
|
||||||
IsSynchronizedWithCurrentItem="False"
|
IsSynchronizedWithCurrentItem="False"
|
||||||
x:Name="lstMenuTrigger"
|
x:Name="lstMenuTrigger"
|
||||||
ItemsSource="{Binding Mode=OneWay, Source={StaticResource ActivationModes}}"
|
ItemsSource="{Binding Mode=OneWay, Source={StaticResource ActivationModes}}"
|
||||||
@@ -431,8 +294,6 @@
|
|||||||
Height="Auto"
|
Height="Auto"
|
||||||
TextWrapping="Wrap"
|
TextWrapping="Wrap"
|
||||||
FontWeight="Bold"
|
FontWeight="Bold"
|
||||||
FontSize="14"><Run
|
FontSize="14"><Run Text="Some Title Goes Here..." Language="de-ch"/></TextBlock>
|
||||||
Text="This window only contains the plumbing. In order to keep things separated, I created a few user controls for the popups and the TaskbarIcon instance."
|
|
||||||
Language="de-ch" /></TextBlock>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
Reference in New Issue
Block a user