mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-02-16 18:49:54 -05:00
Code modernising (#8)
* Applied some code conventions, used more current language features which should improve readability and making it easier to re-factor / modify. Also fixed some typos in documentation. * Changes based on PR conversation for the SystemInfo * Some modifications due to conversations on the PR, especially I removed the FlagsAttribute on the BalloonFlags. * Removed Silverlight targeting in code.
This commit is contained in:
@@ -0,0 +1,109 @@
|
|||||||
|
// Some interop code taken from Mike Marshall's AnyForm
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||||
|
{
|
||||||
|
public class AppBarInfo
|
||||||
|
{
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||||
|
|
||||||
|
[DllImport("shell32.dll")]
|
||||||
|
private static extern uint SHAppBarMessage(uint dwMessage, ref APPBARDATA data);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int SystemParametersInfo(uint uiAction, uint uiParam,
|
||||||
|
IntPtr pvParam, uint fWinIni);
|
||||||
|
|
||||||
|
|
||||||
|
private const int ABE_BOTTOM = 3;
|
||||||
|
private const int ABE_LEFT = 0;
|
||||||
|
private const int ABE_RIGHT = 2;
|
||||||
|
private const int ABE_TOP = 1;
|
||||||
|
|
||||||
|
private const int ABM_GETTASKBARPOS = 0x00000005;
|
||||||
|
|
||||||
|
// SystemParametersInfo constants
|
||||||
|
private const uint SPI_GETWORKAREA = 0x0030;
|
||||||
|
|
||||||
|
private APPBARDATA m_data;
|
||||||
|
|
||||||
|
public ScreenEdge Edge
|
||||||
|
{
|
||||||
|
get { return (ScreenEdge) m_data.uEdge; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle WorkArea
|
||||||
|
{
|
||||||
|
get { return GetRectangle(m_data.rc); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rectangle GetRectangle(RECT rc)
|
||||||
|
{
|
||||||
|
return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetPosition(string strClassName, string strWindowName)
|
||||||
|
{
|
||||||
|
m_data = new APPBARDATA();
|
||||||
|
m_data.cbSize = (uint) Marshal.SizeOf(m_data.GetType());
|
||||||
|
|
||||||
|
IntPtr hWnd = FindWindow(strClassName, strWindowName);
|
||||||
|
|
||||||
|
if (hWnd != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
uint uResult = SHAppBarMessage(ABM_GETTASKBARPOS, ref m_data);
|
||||||
|
|
||||||
|
if (uResult != 1)
|
||||||
|
{
|
||||||
|
throw new Exception("Failed to communicate with the given AppBar");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Failed to find an AppBar that matched the given criteria");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void GetSystemTaskBarPosition()
|
||||||
|
{
|
||||||
|
GetPosition("Shell_TrayWnd", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum ScreenEdge
|
||||||
|
{
|
||||||
|
Undefined = -1,
|
||||||
|
Left = ABE_LEFT,
|
||||||
|
Top = ABE_TOP,
|
||||||
|
Right = ABE_RIGHT,
|
||||||
|
Bottom = ABE_BOTTOM
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
private struct APPBARDATA
|
||||||
|
{
|
||||||
|
public uint cbSize;
|
||||||
|
public IntPtr hWnd;
|
||||||
|
public uint uCallbackMessage;
|
||||||
|
public uint uEdge;
|
||||||
|
public RECT rc;
|
||||||
|
public int lParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
private struct RECT
|
||||||
|
{
|
||||||
|
public int left;
|
||||||
|
public int top;
|
||||||
|
public int right;
|
||||||
|
public int bottom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// the terminating NULL. For Version 5.0 and later, szTip can have a maximum of
|
/// the terminating NULL. For Version 5.0 and later, szTip can have a maximum of
|
||||||
/// 128 characters, including the terminating NULL.
|
/// 128 characters, including the terminating NULL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string ToolTipText;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||||
|
public string ToolTipText;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -66,7 +67,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A value that specifies which bits of the state member are retrieved or modified.
|
/// A value that specifies which bits of the state member are retrieved or modified.
|
||||||
/// For example, setting this member to <see cref="Interop.IconState.Hidden"/>
|
/// For example, setting this member to <see cref="TaskbarNotification.Interop.IconState.Hidden"/>
|
||||||
/// causes only the item's hidden
|
/// causes only the item's hidden
|
||||||
/// state to be retrieved.
|
/// state to be retrieved.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -76,12 +77,13 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// String with the text for a balloon ToolTip. It can have a maximum of 255 characters.
|
/// String with the text for a balloon ToolTip. It can have a maximum of 255 characters.
|
||||||
/// To remove the ToolTip, set the NIF_INFO flag in uFlags and set szInfo to an empty string.
|
/// To remove the ToolTip, set the NIF_INFO flag in uFlags and set szInfo to an empty string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string BalloonText;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||||
|
public string BalloonText;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mainly used to set the version when <see cref="WinApi.Shell_NotifyIcon"/> is invoked
|
/// Mainly used to set the version when <see cref="WinApi.Shell_NotifyIcon"/> is invoked
|
||||||
/// with <see cref="NotifyCommand.SetVersion"/>. However, for legacy operations,
|
/// with <see cref="NotifyCommand.SetVersion"/>. However, for legacy operations,
|
||||||
/// the same member is also used to set timouts for balloon ToolTips.
|
/// the same member is also used to set timeouts for balloon ToolTips.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint VersionOrTimeout;
|
public uint VersionOrTimeout;
|
||||||
|
|
||||||
@@ -89,7 +91,8 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// String containing a title for a balloon ToolTip. This title appears in boldface
|
/// String containing a title for a balloon ToolTip. This title appears in boldface
|
||||||
/// above the text. It can have a maximum of 63 characters.
|
/// above the text. It can have a maximum of 63 characters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string BalloonTitle;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
||||||
|
public string BalloonTitle;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds an icon to a balloon ToolTip, which is placed to the left of the title. If the
|
/// Adds an icon to a balloon ToolTip, which is placed to the left of the title. If the
|
||||||
@@ -108,7 +111,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Windows Vista (Shell32.dll version 6.0.6) and later. The handle of a customized
|
/// Windows Vista (Shell32.dll version 6.0.6) and later. The handle of a customized
|
||||||
/// balloon icon provided by the application that should be used independently
|
/// balloon icon provided by the application that should be used independently
|
||||||
/// of the tray icon. If this member is non-NULL and the <see cref="Interop.BalloonFlags.User"/>
|
/// of the tray icon. If this member is non-NULL and the <see cref="TaskbarNotification.Interop.BalloonFlags.User"/>
|
||||||
/// flag is set, this icon is used as the balloon icon.<br/>
|
/// flag is set, this icon is used as the balloon icon.<br/>
|
||||||
/// If this member is NULL, the legacy behavior is carried out.
|
/// If this member is NULL, the legacy behavior is carried out.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -120,7 +123,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// a hidden taskbar icon without the icon being set.
|
/// a hidden taskbar icon without the icon being set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="handle"></param>
|
/// <param name="handle"></param>
|
||||||
/// <returns></returns>
|
/// <returns>NotifyIconData</returns>
|
||||||
public static NotifyIconData CreateDefault(IntPtr handle)
|
public static NotifyIconData CreateDefault(IntPtr handle)
|
||||||
{
|
{
|
||||||
var data = new NotifyIconData();
|
var data = new NotifyIconData();
|
||||||
@@ -157,7 +160,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
| IconDataMembers.Tip;
|
| IconDataMembers.Tip;
|
||||||
|
|
||||||
//reset strings
|
//reset strings
|
||||||
data.ToolTipText = data.BalloonText = data.BalloonTitle = String.Empty;
|
data.ToolTipText = data.BalloonText = data.BalloonTitle = string.Empty;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,37 +2,34 @@ using System.Windows.Interop;
|
|||||||
|
|
||||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class is a helper for system information, currently to get the DPI factors
|
||||||
|
/// </summary>
|
||||||
public static class SystemInfo
|
public static class SystemInfo
|
||||||
{
|
{
|
||||||
private static System.Windows.Point? dpiFactors;
|
private static readonly System.Windows.Point DpiFactors;
|
||||||
|
|
||||||
private static System.Windows.Point? DpiFactors
|
static SystemInfo()
|
||||||
{
|
{
|
||||||
get
|
|
||||||
{
|
|
||||||
if (dpiFactors == null)
|
|
||||||
using (var source = new HwndSource(new HwndSourceParameters()))
|
using (var source = new HwndSource(new HwndSourceParameters()))
|
||||||
dpiFactors = new System.Windows.Point(source.CompositionTarget.TransformToDevice.M11, source.CompositionTarget.TransformToDevice.M22);
|
{
|
||||||
return dpiFactors;
|
if (source.CompositionTarget?.TransformToDevice != null)
|
||||||
|
{
|
||||||
|
DpiFactors = new System.Windows.Point(source.CompositionTarget.TransformToDevice.M11, source.CompositionTarget.TransformToDevice.M22);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DpiFactors = new System.Windows.Point(1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double DpiXFactor
|
/// <summary>
|
||||||
{
|
/// Returns the DPI X Factor
|
||||||
get
|
/// </summary>
|
||||||
{
|
public static double DpiFactorX => DpiFactors.X;
|
||||||
var factors = DpiFactors;
|
|
||||||
return factors.HasValue ? factors.Value.X : 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double DpiYFactor
|
/// <summary>
|
||||||
{
|
/// Returns the DPI Y Factor
|
||||||
get
|
/// </summary>
|
||||||
{
|
public static double DpiFactorY => DpiFactors.Y;
|
||||||
var factors = DpiFactors;
|
|
||||||
return factors.HasValue ? factors.Value.Y : 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
// Some interop code taken from Mike Marshall's AnyForm
|
// Some interop code taken from Mike Marshall's AnyForm
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||||
{
|
{
|
||||||
@@ -26,25 +22,24 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
Rectangle rcWorkArea = info.WorkArea;
|
Rectangle rcWorkArea = info.WorkArea;
|
||||||
|
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
if (info.Edge == AppBarInfo.ScreenEdge.Left)
|
switch (info.Edge)
|
||||||
{
|
{
|
||||||
|
case AppBarInfo.ScreenEdge.Left:
|
||||||
x = rcWorkArea.Right + space;
|
x = rcWorkArea.Right + space;
|
||||||
y = rcWorkArea.Bottom;
|
y = rcWorkArea.Bottom;
|
||||||
}
|
break;
|
||||||
else if (info.Edge == AppBarInfo.ScreenEdge.Bottom)
|
case AppBarInfo.ScreenEdge.Bottom:
|
||||||
{
|
|
||||||
x = rcWorkArea.Right;
|
x = rcWorkArea.Right;
|
||||||
y = rcWorkArea.Bottom - rcWorkArea.Height - space;
|
y = rcWorkArea.Bottom - rcWorkArea.Height - space;
|
||||||
}
|
break;
|
||||||
else if (info.Edge == AppBarInfo.ScreenEdge.Top)
|
case AppBarInfo.ScreenEdge.Top:
|
||||||
{
|
|
||||||
x = rcWorkArea.Right;
|
x = rcWorkArea.Right;
|
||||||
y = rcWorkArea.Top + rcWorkArea.Height + space;
|
y = rcWorkArea.Top + rcWorkArea.Height + space;
|
||||||
}
|
break;
|
||||||
else if (info.Edge == AppBarInfo.ScreenEdge.Right)
|
case AppBarInfo.ScreenEdge.Right:
|
||||||
{
|
|
||||||
x = rcWorkArea.Right - rcWorkArea.Width - space;
|
x = rcWorkArea.Right - rcWorkArea.Width - space;
|
||||||
y = rcWorkArea.Bottom;
|
y = rcWorkArea.Bottom;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetDeviceCoordinates(new Point {X = x, Y = y});
|
return GetDeviceCoordinates(new Point {X = x, Y = y});
|
||||||
@@ -54,112 +49,15 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// Recalculates OS coordinates in order to support WPFs coordinate
|
/// Recalculates OS coordinates in order to support WPFs coordinate
|
||||||
/// system if OS scaling (DPIs) is not 100%.
|
/// system if OS scaling (DPIs) is not 100%.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="point"></param>
|
/// <param name="point">Point</param>
|
||||||
/// <returns></returns>
|
/// <returns>Point</returns>
|
||||||
public static Point GetDeviceCoordinates(Point point)
|
public static Point GetDeviceCoordinates(Point point)
|
||||||
{
|
{
|
||||||
return new Point() { X = (int)(point.X / SystemInfo.DpiXFactor), Y = (int)(point.Y / SystemInfo.DpiYFactor) };
|
return new Point
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class AppBarInfo
|
|
||||||
{
|
{
|
||||||
[DllImport("user32.dll")]
|
X = (int)(point.X / SystemInfo.DpiFactorX),
|
||||||
private static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
|
Y = (int)(point.Y / SystemInfo.DpiFactorY)
|
||||||
|
};
|
||||||
[DllImport("shell32.dll")]
|
|
||||||
private static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref APPBARDATA data);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam,
|
|
||||||
IntPtr pvParam, UInt32 fWinIni);
|
|
||||||
|
|
||||||
|
|
||||||
private const int ABE_BOTTOM = 3;
|
|
||||||
private const int ABE_LEFT = 0;
|
|
||||||
private const int ABE_RIGHT = 2;
|
|
||||||
private const int ABE_TOP = 1;
|
|
||||||
|
|
||||||
private const int ABM_GETTASKBARPOS = 0x00000005;
|
|
||||||
|
|
||||||
// SystemParametersInfo constants
|
|
||||||
private const UInt32 SPI_GETWORKAREA = 0x0030;
|
|
||||||
|
|
||||||
private APPBARDATA m_data;
|
|
||||||
|
|
||||||
public ScreenEdge Edge
|
|
||||||
{
|
|
||||||
get { return (ScreenEdge) m_data.uEdge; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rectangle WorkArea
|
|
||||||
{
|
|
||||||
get { return GetRectangle(m_data.rc); }
|
|
||||||
}
|
|
||||||
|
|
||||||
private Rectangle GetRectangle(RECT rc)
|
|
||||||
{
|
|
||||||
return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetPosition(string strClassName, string strWindowName)
|
|
||||||
{
|
|
||||||
m_data = new APPBARDATA();
|
|
||||||
m_data.cbSize = (UInt32) Marshal.SizeOf(m_data.GetType());
|
|
||||||
|
|
||||||
IntPtr hWnd = FindWindow(strClassName, strWindowName);
|
|
||||||
|
|
||||||
if (hWnd != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
UInt32 uResult = SHAppBarMessage(ABM_GETTASKBARPOS, ref m_data);
|
|
||||||
|
|
||||||
if (uResult != 1)
|
|
||||||
{
|
|
||||||
throw new Exception("Failed to communicate with the given AppBar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Failed to find an AppBar that matched the given criteria");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void GetSystemTaskBarPosition()
|
|
||||||
{
|
|
||||||
GetPosition("Shell_TrayWnd", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public enum ScreenEdge
|
|
||||||
{
|
|
||||||
Undefined = -1,
|
|
||||||
Left = ABE_LEFT,
|
|
||||||
Top = ABE_TOP,
|
|
||||||
Right = ABE_RIGHT,
|
|
||||||
Bottom = ABE_BOTTOM
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
private struct APPBARDATA
|
|
||||||
{
|
|
||||||
public UInt32 cbSize;
|
|
||||||
public IntPtr hWnd;
|
|
||||||
public UInt32 uCallbackMessage;
|
|
||||||
public UInt32 uEdge;
|
|
||||||
public RECT rc;
|
|
||||||
public Int32 lParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
private struct RECT
|
|
||||||
{
|
|
||||||
public Int32 left;
|
|
||||||
public Int32 top;
|
|
||||||
public Int32 right;
|
|
||||||
public Int32 bottom;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,8 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class WinApi
|
internal static class WinApi
|
||||||
{
|
{
|
||||||
|
private const string User32 = "user32.dll";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates, updates or deletes the taskbar icon.
|
/// Creates, updates or deletes the taskbar icon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -18,7 +20,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the helper window that receives messages from the taskar icon.
|
/// Creates the helper window that receives messages from the taskar icon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport("USER32.DLL", EntryPoint = "CreateWindowExW", SetLastError = true)]
|
[DllImport(User32, EntryPoint = "CreateWindowExW", SetLastError = true)]
|
||||||
public static extern IntPtr CreateWindowEx(int dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
|
public static extern IntPtr CreateWindowEx(int dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
|
||||||
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, int dwStyle, int x, int y,
|
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, int dwStyle, int x, int y,
|
||||||
int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
|
int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
|
||||||
@@ -28,21 +30,21 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes a default windows procedure.
|
/// Processes a default windows procedure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport("USER32.DLL")]
|
[DllImport(User32)]
|
||||||
public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wparam, IntPtr lparam);
|
public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wparam, IntPtr lparam);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers the helper window class.
|
/// Registers the helper window class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport("USER32.DLL", EntryPoint = "RegisterClassW", SetLastError = true)]
|
[DllImport(User32, EntryPoint = "RegisterClassW", SetLastError = true)]
|
||||||
public static extern short RegisterClass(ref WindowClass lpWndClass);
|
public static extern short RegisterClass(ref WindowClass lpWndClass);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers a listener for a window message.
|
/// Registers a listener for a window message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="lpString"></param>
|
/// <param name="lpString"></param>
|
||||||
/// <returns></returns>
|
/// <returns>uint</returns>
|
||||||
[DllImport("User32.Dll", EntryPoint = "RegisterWindowMessageW")]
|
[DllImport(User32, EntryPoint = "RegisterWindowMessageW")]
|
||||||
public static extern uint RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString);
|
public static extern uint RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -50,8 +52,8 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// taskbar icon.
|
/// taskbar icon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hWnd"></param>
|
/// <param name="hWnd"></param>
|
||||||
/// <returns></returns>
|
/// <returns>bool</returns>
|
||||||
[DllImport("USER32.DLL", SetLastError = true)]
|
[DllImport(User32, SetLastError = true)]
|
||||||
public static extern bool DestroyWindow(IntPtr hWnd);
|
public static extern bool DestroyWindow(IntPtr hWnd);
|
||||||
|
|
||||||
|
|
||||||
@@ -59,8 +61,8 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// Gives focus to a given window.
|
/// Gives focus to a given window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hWnd"></param>
|
/// <param name="hWnd"></param>
|
||||||
/// <returns></returns>
|
/// <returns>bool</returns>
|
||||||
[DllImport("USER32.DLL")]
|
[DllImport(User32)]
|
||||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||||
|
|
||||||
|
|
||||||
@@ -72,18 +74,18 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// <returns>The maximum amount of time, in milliseconds, that can
|
/// <returns>The maximum amount of time, in milliseconds, that can
|
||||||
/// elapse between a first click and a second click for the OS to
|
/// elapse between a first click and a second click for the OS to
|
||||||
/// consider the mouse action a double-click.</returns>
|
/// consider the mouse action a double-click.</returns>
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
|
[DllImport(User32, CharSet = CharSet.Auto, ExactSpelling = true)]
|
||||||
public static extern int GetDoubleClickTime();
|
public static extern int GetDoubleClickTime();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the screen coordinates of the current mouse position.
|
/// Gets the screen coordinates of the current mouse position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport("USER32.DLL", SetLastError = true)]
|
[DllImport(User32, SetLastError = true)]
|
||||||
public static extern bool GetPhysicalCursorPos(ref Point lpPoint);
|
public static extern bool GetPhysicalCursorPos(ref Point lpPoint);
|
||||||
|
|
||||||
|
|
||||||
[DllImport("USER32.DLL", SetLastError = true)]
|
[DllImport(User32, SetLastError = true)]
|
||||||
public static extern bool GetCursorPos(ref Point lpPoint);
|
public static extern bool GetCursorPos(ref Point lpPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// Callback delegate which is used by the Windows API to
|
/// Callback delegate which is used by the Windows API to
|
||||||
/// submit window messages.
|
/// submit window messages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate IntPtr WindowProcedureHandler(IntPtr hwnd, uint uMsg, IntPtr wparam, IntPtr lparam);
|
public delegate IntPtr WindowProcedureHandler(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// pointer rather than a real window handler.<br/>
|
/// pointer rather than a real window handler.<br/>
|
||||||
/// Used at design time.
|
/// Used at design time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns>WindowMessageSink</returns>
|
||||||
internal static WindowMessageSink CreateEmpty()
|
internal static WindowMessageSink CreateEmpty()
|
||||||
{
|
{
|
||||||
return new WindowMessageSink
|
return new WindowMessageSink
|
||||||
@@ -169,7 +169,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
wc.hIcon = IntPtr.Zero;
|
wc.hIcon = IntPtr.Zero;
|
||||||
wc.hCursor = IntPtr.Zero;
|
wc.hCursor = IntPtr.Zero;
|
||||||
wc.hbrBackground = IntPtr.Zero;
|
wc.hbrBackground = IntPtr.Zero;
|
||||||
wc.lpszMenuName = "";
|
wc.lpszMenuName = string.Empty;
|
||||||
wc.lpszClassName = WindowId;
|
wc.lpszClassName = WindowId;
|
||||||
|
|
||||||
// Register the window class
|
// Register the window class
|
||||||
@@ -185,11 +185,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
|
|
||||||
if (MessageWindowHandle == IntPtr.Zero)
|
if (MessageWindowHandle == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
#if SILVERLIGHT
|
|
||||||
throw new Exception("Message window handle was not a valid pointer.");
|
|
||||||
#else
|
|
||||||
throw new Win32Exception("Message window handle was not a valid pointer");
|
throw new Win32Exception("Message window handle was not a valid pointer");
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,20 +196,20 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Callback method that receives messages from the taskbar area.
|
/// Callback method that receives messages from the taskbar area.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IntPtr OnWindowMessageReceived(IntPtr hwnd, uint messageId, IntPtr wparam, IntPtr lparam)
|
private IntPtr OnWindowMessageReceived(IntPtr hWnd, uint messageId, IntPtr wParam, IntPtr lParam)
|
||||||
{
|
{
|
||||||
if (messageId == taskbarRestartMessageId)
|
if (messageId == taskbarRestartMessageId)
|
||||||
{
|
{
|
||||||
//recreate the icon if the taskbar was restarted (e.g. due to Win Explorer shutdown)
|
//recreate the icon if the taskbar was restarted (e.g. due to Win Explorer shutdown)
|
||||||
var listener = TaskbarCreated;
|
var listener = TaskbarCreated;
|
||||||
if(listener != null) listener();
|
listener?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
//forward message
|
//forward message
|
||||||
ProcessWindowMessage(messageId, wparam, lparam);
|
ProcessWindowMessage(messageId, wParam, lParam);
|
||||||
|
|
||||||
// Pass the message to the default window procedure
|
// Pass the message to the default window procedure
|
||||||
return WinApi.DefWindowProc(hwnd, messageId, wparam, lparam);
|
return WinApi.DefWindowProc(hWnd, messageId, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -278,13 +274,13 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
|
|
||||||
case 0x402:
|
case 0x402:
|
||||||
var listener = BalloonToolTipChanged;
|
var listener = BalloonToolTipChanged;
|
||||||
if (listener != null) listener(true);
|
listener?.Invoke(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x403:
|
case 0x403:
|
||||||
case 0x404:
|
case 0x404:
|
||||||
listener = BalloonToolTipChanged;
|
listener = BalloonToolTipChanged;
|
||||||
if (listener != null) listener(false);
|
listener?.Invoke(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x405:
|
case 0x405:
|
||||||
@@ -293,12 +289,12 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
|
|
||||||
case 0x406:
|
case 0x406:
|
||||||
listener = ChangeToolTipStateRequest;
|
listener = ChangeToolTipStateRequest;
|
||||||
if (listener != null) listener(true);
|
listener?.Invoke(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x407:
|
case 0x407:
|
||||||
listener = ChangeToolTipStateRequest;
|
listener = ChangeToolTipStateRequest;
|
||||||
if (listener != null) listener(false);
|
listener?.Invoke(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -328,7 +324,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
|
||||||
// This object will be cleaned up by the Dispose method.
|
// This object will be cleaned up by the Dispose method.
|
||||||
// Therefore, you should call GC.SupressFinalize to
|
// Therefore, you should call GC.SuppressFinalize to
|
||||||
// take this object off the finalization queue
|
// take this object off the finalization queue
|
||||||
// and prevent finalization code for this object
|
// and prevent finalization code for this object
|
||||||
// from executing a second time.
|
// from executing a second time.
|
||||||
@@ -340,7 +336,7 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// method does not get called. This gives this base class the
|
/// method does not get called. This gives this base class the
|
||||||
/// opportunity to finalize.
|
/// opportunity to finalize.
|
||||||
/// <para>
|
/// <para>
|
||||||
/// Important: Do not provide destructors in types derived from
|
/// Important: Do not provide destructor in types derived from
|
||||||
/// this class.
|
/// this class.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Runtime.InteropServices;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Markup;
|
using System.Windows.Markup;
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <param name="args">RoutedEventArgs to use when raising the event</param>
|
/// <param name="args">RoutedEventArgs to use when raising the event</param>
|
||||||
internal static void RaiseEvent(DependencyObject target, RoutedEventArgs args)
|
internal static void RaiseEvent(DependencyObject target, RoutedEventArgs args)
|
||||||
{
|
{
|
||||||
if (target is UIElement)
|
if (target is UIElement uiElement)
|
||||||
{
|
{
|
||||||
(target as UIElement).RaiseEvent(args);
|
uiElement.RaiseEvent(args);
|
||||||
}
|
}
|
||||||
else if (target is ContentElement)
|
else if (target is ContentElement contentElement)
|
||||||
{
|
{
|
||||||
(target as ContentElement).RaiseEvent(args);
|
contentElement.RaiseEvent(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,20 +37,15 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <param name="handler">Event handler to be added</param>
|
/// <param name="handler">Event handler to be added</param>
|
||||||
internal static void AddHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler)
|
internal static void AddHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler)
|
||||||
{
|
{
|
||||||
UIElement uie = element as UIElement;
|
if (element is UIElement uie)
|
||||||
if (uie != null)
|
|
||||||
{
|
{
|
||||||
uie.AddHandler(routedEvent, handler);
|
uie.AddHandler(routedEvent, handler);
|
||||||
}
|
}
|
||||||
else
|
else if (element is ContentElement ce)
|
||||||
{
|
|
||||||
ContentElement ce = element as ContentElement;
|
|
||||||
if (ce != null)
|
|
||||||
{
|
{
|
||||||
ce.AddHandler(routedEvent, handler);
|
ce.AddHandler(routedEvent, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A static helper method that removes a handler for a routed event
|
/// A static helper method that removes a handler for a routed event
|
||||||
@@ -61,20 +56,15 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <param name="handler">Event handler to be removed</param>
|
/// <param name="handler">Event handler to be removed</param>
|
||||||
internal static void RemoveHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler)
|
internal static void RemoveHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler)
|
||||||
{
|
{
|
||||||
UIElement uie = element as UIElement;
|
if (element is UIElement uie)
|
||||||
if (uie != null)
|
|
||||||
{
|
{
|
||||||
uie.RemoveHandler(routedEvent, handler);
|
uie.RemoveHandler(routedEvent, handler);
|
||||||
}
|
}
|
||||||
else
|
else if (element is ContentElement ce)
|
||||||
{
|
|
||||||
ContentElement ce = element as ContentElement;
|
|
||||||
if (ce != null)
|
|
||||||
{
|
{
|
||||||
ce.RemoveHandler(routedEvent, handler);
|
ce.RemoveHandler(routedEvent, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// TrayPopupResolved Read-Only Dependency Property
|
/// TrayPopupResolved Read-Only Dependency Property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly DependencyPropertyKey TrayPopupResolvedPropertyKey
|
private static readonly DependencyPropertyKey TrayPopupResolvedPropertyKey
|
||||||
= DependencyProperty.RegisterReadOnly("TrayPopupResolved", typeof (Popup), typeof (TaskbarIcon),
|
= DependencyProperty.RegisterReadOnly(nameof(TrayPopupResolved), typeof (Popup), typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// TrayToolTipResolved Read-Only Dependency Property
|
/// TrayToolTipResolved Read-Only Dependency Property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly DependencyPropertyKey TrayToolTipResolvedPropertyKey
|
private static readonly DependencyPropertyKey TrayToolTipResolvedPropertyKey
|
||||||
= DependencyProperty.RegisterReadOnly("TrayToolTipResolved", typeof (ToolTip), typeof (TaskbarIcon),
|
= DependencyProperty.RegisterReadOnly(nameof(TrayToolTipResolved), typeof (ToolTip), typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
|
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// CustomBalloon Read-Only Dependency Property
|
/// CustomBalloon Read-Only Dependency Property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly DependencyPropertyKey CustomBalloonPropertyKey
|
private static readonly DependencyPropertyKey CustomBalloonPropertyKey
|
||||||
= DependencyProperty.RegisterReadOnly("CustomBalloon", typeof (Popup), typeof (TaskbarIcon),
|
= DependencyProperty.RegisterReadOnly(nameof(CustomBalloon), typeof (Popup), typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -198,7 +198,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// Resolves an image source and updates the <see cref="Icon" /> property accordingly.
|
/// Resolves an image source and updates the <see cref="Icon" /> property accordingly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty IconSourceProperty =
|
public static readonly DependencyProperty IconSourceProperty =
|
||||||
DependencyProperty.Register("IconSource",
|
DependencyProperty.Register(nameof(IconSource),
|
||||||
typeof (ImageSource),
|
typeof (ImageSource),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null, IconSourcePropertyChanged));
|
new FrameworkPropertyMetadata(null, IconSourcePropertyChanged));
|
||||||
@@ -256,10 +256,10 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// was set or if custom tooltips are not supported.
|
/// was set or if custom tooltips are not supported.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty ToolTipTextProperty =
|
public static readonly DependencyProperty ToolTipTextProperty =
|
||||||
DependencyProperty.Register("ToolTipText",
|
DependencyProperty.Register(nameof(ToolTipText),
|
||||||
typeof (string),
|
typeof (string),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(String.Empty, ToolTipTextPropertyChanged));
|
new FrameworkPropertyMetadata(string.Empty, ToolTipTextPropertyChanged));
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -330,7 +330,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// the <see cref="ToolTipText"/> property is set as well.
|
/// the <see cref="ToolTipText"/> property is set as well.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty TrayToolTipProperty =
|
public static readonly DependencyProperty TrayToolTipProperty =
|
||||||
DependencyProperty.Register("TrayToolTip",
|
DependencyProperty.Register(nameof(TrayToolTip),
|
||||||
typeof (UIElement),
|
typeof (UIElement),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null, TrayToolTipPropertyChanged));
|
new FrameworkPropertyMetadata(null, TrayToolTipPropertyChanged));
|
||||||
@@ -404,7 +404,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// A control that is displayed as a popup when the taskbar icon is clicked.
|
/// A control that is displayed as a popup when the taskbar icon is clicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty TrayPopupProperty =
|
public static readonly DependencyProperty TrayPopupProperty =
|
||||||
DependencyProperty.Register("TrayPopup",
|
DependencyProperty.Register(nameof(TrayPopup),
|
||||||
typeof (UIElement),
|
typeof (UIElement),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null, TrayPopupPropertyChanged));
|
new FrameworkPropertyMetadata(null, TrayPopupPropertyChanged));
|
||||||
@@ -473,7 +473,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// Defaults to <see cref="PopupActivationMode.RightClick"/>.
|
/// Defaults to <see cref="PopupActivationMode.RightClick"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty MenuActivationProperty =
|
public static readonly DependencyProperty MenuActivationProperty =
|
||||||
DependencyProperty.Register("MenuActivation",
|
DependencyProperty.Register(nameof(MenuActivation),
|
||||||
typeof (PopupActivationMode),
|
typeof (PopupActivationMode),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(PopupActivationMode.RightClick));
|
new FrameworkPropertyMetadata(PopupActivationMode.RightClick));
|
||||||
@@ -501,7 +501,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// Default is <see cref="PopupActivationMode.LeftClick" />.
|
/// Default is <see cref="PopupActivationMode.LeftClick" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty PopupActivationProperty =
|
public static readonly DependencyProperty PopupActivationProperty =
|
||||||
DependencyProperty.Register("PopupActivation",
|
DependencyProperty.Register(nameof(PopupActivation),
|
||||||
typeof (PopupActivationMode),
|
typeof (PopupActivationMode),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(PopupActivationMode.LeftClick));
|
new FrameworkPropertyMetadata(PopupActivationMode.LeftClick));
|
||||||
@@ -673,7 +673,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// double clicked.
|
/// double clicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty DoubleClickCommandProperty =
|
public static readonly DependencyProperty DoubleClickCommandProperty =
|
||||||
DependencyProperty.Register("DoubleClickCommand",
|
DependencyProperty.Register(nameof(DoubleClickCommand),
|
||||||
typeof (ICommand),
|
typeof (ICommand),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
@@ -700,7 +700,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// Command parameter for the <see cref="DoubleClickCommand"/>.
|
/// Command parameter for the <see cref="DoubleClickCommand"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty DoubleClickCommandParameterProperty =
|
public static readonly DependencyProperty DoubleClickCommandParameterProperty =
|
||||||
DependencyProperty.Register("DoubleClickCommandParameter",
|
DependencyProperty.Register(nameof(DoubleClickCommandParameter),
|
||||||
typeof (object),
|
typeof (object),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
@@ -726,7 +726,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// The target of the command that is fired if the notify icon is double clicked.
|
/// The target of the command that is fired if the notify icon is double clicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty DoubleClickCommandTargetProperty =
|
public static readonly DependencyProperty DoubleClickCommandTargetProperty =
|
||||||
DependencyProperty.Register("DoubleClickCommandTarget",
|
DependencyProperty.Register(nameof(DoubleClickCommandTarget),
|
||||||
typeof (IInputElement),
|
typeof (IInputElement),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
@@ -753,7 +753,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// double clicked.
|
/// double clicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty LeftClickCommandProperty =
|
public static readonly DependencyProperty LeftClickCommandProperty =
|
||||||
DependencyProperty.Register("LeftClickCommand",
|
DependencyProperty.Register(nameof(LeftClickCommand),
|
||||||
typeof (ICommand),
|
typeof (ICommand),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
@@ -780,7 +780,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// Command parameter for the <see cref="LeftClickCommand"/>.
|
/// Command parameter for the <see cref="LeftClickCommand"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty LeftClickCommandParameterProperty =
|
public static readonly DependencyProperty LeftClickCommandParameterProperty =
|
||||||
DependencyProperty.Register("LeftClickCommandParameter",
|
DependencyProperty.Register(nameof(LeftClickCommandParameter),
|
||||||
typeof (object),
|
typeof (object),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
@@ -807,7 +807,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// The target of the command that is fired if the notify icon is clicked.
|
/// The target of the command that is fired if the notify icon is clicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty LeftClickCommandTargetProperty =
|
public static readonly DependencyProperty LeftClickCommandTargetProperty =
|
||||||
DependencyProperty.Register("LeftClickCommandTarget",
|
DependencyProperty.Register(nameof(LeftClickCommandTarget),
|
||||||
typeof (IInputElement),
|
typeof (IInputElement),
|
||||||
typeof (TaskbarIcon),
|
typeof (TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(null));
|
new FrameworkPropertyMetadata(null));
|
||||||
@@ -834,7 +834,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// Set to true to make left clicks work without delay.
|
/// Set to true to make left clicks work without delay.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty NoLeftClickDelayProperty =
|
public static readonly DependencyProperty NoLeftClickDelayProperty =
|
||||||
DependencyProperty.Register("NoLeftClickDelay",
|
DependencyProperty.Register(nameof(NoLeftClickDelay),
|
||||||
typeof(bool),
|
typeof(bool),
|
||||||
typeof(TaskbarIcon),
|
typeof(TaskbarIcon),
|
||||||
new FrameworkPropertyMetadata(false));
|
new FrameworkPropertyMetadata(false));
|
||||||
@@ -893,8 +893,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayLeftMouseDownEvent);
|
||||||
args.RoutedEvent = TrayLeftMouseDownEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -935,8 +934,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayRightMouseDownEvent);
|
||||||
args.RoutedEvent = TrayRightMouseDownEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -977,8 +975,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayMiddleMouseDownEvent);
|
||||||
args.RoutedEvent = TrayMiddleMouseDownEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1018,8 +1015,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayLeftMouseUpEvent);
|
||||||
args.RoutedEvent = TrayLeftMouseUpEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1059,8 +1055,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayRightMouseUpEvent);
|
||||||
args.RoutedEvent = TrayRightMouseUpEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1101,8 +1096,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayMiddleMouseUpEvent);
|
||||||
args.RoutedEvent = TrayMiddleMouseUpEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1145,8 +1139,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayMouseDoubleClickEvent);
|
||||||
args.RoutedEvent = TrayMouseDoubleClickEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1186,8 +1179,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
var args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayMouseMoveEvent);
|
||||||
args.RoutedEvent = TrayMouseMoveEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1228,8 +1220,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayBalloonTipShownEvent);
|
||||||
args.RoutedEvent = TrayBalloonTipShownEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1270,8 +1261,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayBalloonTipClosedEvent);
|
||||||
args.RoutedEvent = TrayBalloonTipClosedEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1312,8 +1302,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayBalloonTipClickedEvent);
|
||||||
args.RoutedEvent = TrayBalloonTipClickedEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1354,8 +1343,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayContextMenuOpenEvent);
|
||||||
args.RoutedEvent = TrayContextMenuOpenEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1392,8 +1380,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(PreviewTrayContextMenuOpenEvent);
|
||||||
args.RoutedEvent = PreviewTrayContextMenuOpenEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1433,8 +1420,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayPopupOpenEvent);
|
||||||
args.RoutedEvent = TrayPopupOpenEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1471,8 +1457,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(PreviewTrayPopupOpenEvent);
|
||||||
args.RoutedEvent = PreviewTrayPopupOpenEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1512,8 +1497,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayToolTipOpenEvent);
|
||||||
args.RoutedEvent = TrayToolTipOpenEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1550,8 +1534,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(PreviewTrayToolTipOpenEvent);
|
||||||
args.RoutedEvent = PreviewTrayToolTipOpenEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1591,8 +1574,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(TrayToolTipCloseEvent);
|
||||||
args.RoutedEvent = TrayToolTipCloseEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1629,8 +1611,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(PreviewTrayToolTipCloseEvent);
|
||||||
args.RoutedEvent = PreviewTrayToolTipCloseEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1675,8 +1656,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(PopupOpenedEvent);
|
||||||
args.RoutedEvent = PopupOpenedEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1719,8 +1699,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(ToolTipOpenedEvent);
|
||||||
args.RoutedEvent = ToolTipOpenedEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1763,8 +1742,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
RoutedEventArgs args = new RoutedEventArgs();
|
RoutedEventArgs args = new RoutedEventArgs(ToolTipCloseEvent);
|
||||||
args.RoutedEvent = ToolTipCloseEvent;
|
|
||||||
RoutedEventHelper.RaiseEvent(target, args);
|
RoutedEventHelper.RaiseEvent(target, args);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@@ -1864,7 +1842,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
#region ParentTaskbarIcon
|
#region ParentTaskbarIcon
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An attached property that is assigned to displayed UI elements (balloos, tooltips, context menus), and
|
/// An attached property that is assigned to displayed UI elements (balloons, tooltips, context menus), and
|
||||||
/// that can be used to bind to this control. The attached property is being derived, so binding is
|
/// that can be used to bind to this control. The attached property is being derived, so binding is
|
||||||
/// quite straightforward:
|
/// quite straightforward:
|
||||||
/// <code>
|
/// <code>
|
||||||
@@ -1907,11 +1885,11 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
VisibilityProperty.OverrideMetadata(typeof (TaskbarIcon), md);
|
VisibilityProperty.OverrideMetadata(typeof (TaskbarIcon), md);
|
||||||
|
|
||||||
//register change listener for the DataContext property
|
//register change listener for the DataContext property
|
||||||
md = new FrameworkPropertyMetadata(new PropertyChangedCallback(DataContextPropertyChanged));
|
md = new FrameworkPropertyMetadata(DataContextPropertyChanged);
|
||||||
DataContextProperty.OverrideMetadata(typeof (TaskbarIcon), md);
|
DataContextProperty.OverrideMetadata(typeof (TaskbarIcon), md);
|
||||||
|
|
||||||
//register change listener for the ContextMenu property
|
//register change listener for the ContextMenu property
|
||||||
md = new FrameworkPropertyMetadata(new PropertyChangedCallback(ContextMenuPropertyChanged));
|
md = new FrameworkPropertyMetadata(ContextMenuPropertyChanged);
|
||||||
ContextMenuProperty.OverrideMetadata(typeof (TaskbarIcon), md);
|
ContextMenuProperty.OverrideMetadata(typeof (TaskbarIcon), md);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class TaskbarIcon : FrameworkElement, IDisposable
|
public partial class TaskbarIcon : FrameworkElement, IDisposable
|
||||||
{
|
{
|
||||||
|
private readonly object lockObject = new object();
|
||||||
|
|
||||||
#region Members
|
#region Members
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -70,10 +72,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time we should wait for a double click.
|
/// The time we should wait for a double click.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int DoubleClickWaitTime
|
private int DoubleClickWaitTime => NoLeftClickDelay ? 0 : WinApi.GetDoubleClickTime();
|
||||||
{
|
|
||||||
get { return NoLeftClickDelay ? 0 : WinApi.GetDoubleClickTime(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A timer that is used to close open balloon tooltips.
|
/// A timer that is used to close open balloon tooltips.
|
||||||
@@ -90,10 +89,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// on the OS. Windows Vista or higher is required in order to
|
/// on the OS. Windows Vista or higher is required in order to
|
||||||
/// support this feature.
|
/// support this feature.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool SupportsCustomToolTips
|
public bool SupportsCustomToolTips => messageSink.Version == NotifyIconVersion.Vista;
|
||||||
{
|
|
||||||
get { return messageSink.Version == NotifyIconVersion.Vista; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -113,50 +109,61 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double scalingFactor = double.NaN;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Construction
|
#region Construction
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Inits the taskbar icon and registers a message listener
|
/// Initializes the taskbar icon and registers a message listener
|
||||||
/// in order to receive events from the taskbar area.
|
/// in order to receive events from the taskbar area.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TaskbarIcon()
|
public TaskbarIcon()
|
||||||
{
|
{
|
||||||
//using dummy sink in design mode
|
// using dummy sink in design mode
|
||||||
messageSink = Util.IsDesignMode
|
messageSink = Util.IsDesignMode
|
||||||
? WindowMessageSink.CreateEmpty()
|
? WindowMessageSink.CreateEmpty()
|
||||||
: new WindowMessageSink(NotifyIconVersion.Win95);
|
: new WindowMessageSink(NotifyIconVersion.Win95);
|
||||||
|
|
||||||
//init icon data structure
|
// init icon data structure
|
||||||
iconData = NotifyIconData.CreateDefault(messageSink.MessageWindowHandle);
|
iconData = NotifyIconData.CreateDefault(messageSink.MessageWindowHandle);
|
||||||
|
|
||||||
//create the taskbar icon
|
// create the taskbar icon
|
||||||
CreateTaskbarIcon();
|
CreateTaskbarIcon();
|
||||||
|
|
||||||
//register event listeners
|
// register event listeners
|
||||||
messageSink.MouseEventReceived += OnMouseEvent;
|
messageSink.MouseEventReceived += OnMouseEvent;
|
||||||
messageSink.TaskbarCreated += OnTaskbarCreated;
|
messageSink.TaskbarCreated += OnTaskbarCreated;
|
||||||
messageSink.ChangeToolTipStateRequest += OnToolTipChange;
|
messageSink.ChangeToolTipStateRequest += OnToolTipChange;
|
||||||
messageSink.BalloonToolTipChanged += OnBalloonToolTipChanged;
|
messageSink.BalloonToolTipChanged += OnBalloonToolTipChanged;
|
||||||
|
|
||||||
//init single click / balloon timers
|
// init single click / balloon timers
|
||||||
singleClickTimer = new Timer(DoSingleClickAction);
|
singleClickTimer = new Timer(DoSingleClickAction);
|
||||||
balloonCloseTimer = new Timer(CloseBalloonCallback);
|
balloonCloseTimer = new Timer(CloseBalloonCallback);
|
||||||
|
|
||||||
//register listener in order to get notified when the application closes
|
// register listener in order to get notified when the application closes
|
||||||
if (Application.Current != null) Application.Current.Exit += OnExit;
|
if (Application.Current != null)
|
||||||
|
{
|
||||||
|
Application.Current.Exit += OnExit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Custom Balloons
|
#region Custom Balloons
|
||||||
|
/// <summary>
|
||||||
|
/// A delegate to handle customer popup positions.
|
||||||
|
/// </summary>
|
||||||
public delegate Point GetCustomPopupPosition();
|
public delegate Point GetCustomPopupPosition();
|
||||||
|
|
||||||
public GetCustomPopupPosition CustomPopupPosition;
|
/// <summary>
|
||||||
|
/// Specify a custom popup position
|
||||||
|
/// </summary>
|
||||||
|
public GetCustomPopupPosition CustomPopupPosition { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the location of the system tray
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Point</returns>
|
||||||
public Point GetPopupTrayPosition()
|
public Point GetPopupTrayPosition()
|
||||||
{
|
{
|
||||||
return TrayInfo.GetTrayLocation();
|
return TrayInfo.GetTrayLocation();
|
||||||
@@ -168,13 +175,13 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <param name="balloon"></param>
|
/// <param name="balloon"></param>
|
||||||
/// <param name="animation">An optional animation for the popup.</param>
|
/// <param name="animation">An optional animation for the popup.</param>
|
||||||
/// <param name="timeout">The time after which the popup is being closed.
|
/// <param name="timeout">The time after which the popup is being closed.
|
||||||
/// Submit null in order to keep the balloon open inde
|
/// Submit null in order to keep the balloon open indefinitely
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <exception cref="ArgumentNullException">If <paramref name="balloon"/>
|
/// <exception cref="ArgumentNullException">If <paramref name="balloon"/>
|
||||||
/// is a null reference.</exception>
|
/// is a null reference.</exception>
|
||||||
public void ShowCustomBalloon(UIElement balloon, PopupAnimation animation, int? timeout)
|
public void ShowCustomBalloon(UIElement balloon, PopupAnimation animation, int? timeout)
|
||||||
{
|
{
|
||||||
Dispatcher dispatcher = this.GetDispatcher();
|
var dispatcher = this.GetDispatcher();
|
||||||
if (!dispatcher.CheckAccess())
|
if (!dispatcher.CheckAccess())
|
||||||
{
|
{
|
||||||
var action = new Action(() => ShowCustomBalloon(balloon, animation, timeout));
|
var action = new Action(() => ShowCustomBalloon(balloon, animation, timeout));
|
||||||
@@ -182,45 +189,45 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (balloon == null) throw new ArgumentNullException("balloon");
|
if (balloon == null) throw new ArgumentNullException(nameof(balloon));
|
||||||
if (timeout.HasValue && timeout < 500)
|
if (timeout.HasValue && timeout < 500)
|
||||||
{
|
{
|
||||||
string msg = "Invalid timeout of {0} milliseconds. Timeout must be at least 500 ms";
|
string msg = "Invalid timeout of {0} milliseconds. Timeout must be at least 500 ms";
|
||||||
msg = String.Format(msg, timeout);
|
msg = string.Format(msg, timeout);
|
||||||
throw new ArgumentOutOfRangeException("timeout", msg);
|
throw new ArgumentOutOfRangeException(nameof(timeout), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsureNotDisposed();
|
EnsureNotDisposed();
|
||||||
|
|
||||||
//make sure we don't have an open balloon
|
// make sure we don't have an open balloon
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
CloseBalloon();
|
CloseBalloon();
|
||||||
}
|
}
|
||||||
|
|
||||||
//create an invisible popup that hosts the UIElement
|
// create an invisible popup that hosts the UIElement
|
||||||
Popup popup = new Popup();
|
Popup popup = new Popup
|
||||||
popup.AllowsTransparency = true;
|
{
|
||||||
|
AllowsTransparency = true
|
||||||
|
};
|
||||||
|
|
||||||
//provide the popup with the taskbar icon's data context
|
// provide the popup with the taskbar icon's data context
|
||||||
UpdateDataContext(popup, null, DataContext);
|
UpdateDataContext(popup, null, DataContext);
|
||||||
|
|
||||||
//don't animate by default - devs can use attached
|
// don't animate by default - developers can use attached events or override
|
||||||
//events or override
|
|
||||||
popup.PopupAnimation = animation;
|
popup.PopupAnimation = animation;
|
||||||
|
|
||||||
//in case the balloon is cleaned up through routed events, the
|
// in case the balloon is cleaned up through routed events, the
|
||||||
//control didn't remove the balloon from its parent popup when
|
// control didn't remove the balloon from its parent popup when
|
||||||
//if was closed the last time - just make sure it doesn't have
|
// if was closed the last time - just make sure it doesn't have
|
||||||
//a parent that is a popup
|
// a parent that is a popup
|
||||||
var parent = LogicalTreeHelper.GetParent(balloon) as Popup;
|
var parent = LogicalTreeHelper.GetParent(balloon) as Popup;
|
||||||
if (parent != null) parent.Child = null;
|
if (parent != null) parent.Child = null;
|
||||||
|
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
{
|
{
|
||||||
string msg =
|
string msg = "Cannot display control [{0}] in a new balloon popup - that control already has a parent. You may consider creating new balloons every time you want to show one.";
|
||||||
"Cannot display control [{0}] in a new balloon popup - that control already has a parent. You may consider creating new balloons every time you want to show one.";
|
msg = string.Format(msg, balloon);
|
||||||
msg = String.Format(msg, balloon);
|
|
||||||
throw new InvalidOperationException(msg);
|
throw new InvalidOperationException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,28 +241,28 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
popup.StaysOpen = true;
|
popup.StaysOpen = true;
|
||||||
|
|
||||||
|
|
||||||
Point position = this.CustomPopupPosition != null ? this.CustomPopupPosition() : this.GetPopupTrayPosition();
|
Point position = CustomPopupPosition != null ? CustomPopupPosition() : GetPopupTrayPosition();
|
||||||
popup.HorizontalOffset = position.X - 1;
|
popup.HorizontalOffset = position.X - 1;
|
||||||
popup.VerticalOffset = position.Y - 1;
|
popup.VerticalOffset = position.Y - 1;
|
||||||
|
|
||||||
//store reference
|
//store reference
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
SetCustomBalloon(popup);
|
SetCustomBalloon(popup);
|
||||||
}
|
}
|
||||||
|
|
||||||
//assign this instance as an attached property
|
// assign this instance as an attached property
|
||||||
SetParentTaskbarIcon(balloon, this);
|
SetParentTaskbarIcon(balloon, this);
|
||||||
|
|
||||||
//fire attached event
|
// fire attached event
|
||||||
RaiseBalloonShowingEvent(balloon, this);
|
RaiseBalloonShowingEvent(balloon, this);
|
||||||
|
|
||||||
//display item
|
// display item
|
||||||
popup.IsOpen = true;
|
popup.IsOpen = true;
|
||||||
|
|
||||||
if (timeout.HasValue)
|
if (timeout.HasValue)
|
||||||
{
|
{
|
||||||
//register timer to close the popup
|
// register timer to close the popup
|
||||||
balloonCloseTimer.Change(timeout.Value, Timeout.Infinite);
|
balloonCloseTimer.Change(timeout.Value, Timeout.Infinite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,7 +279,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (IsDisposed) return;
|
if (IsDisposed) return;
|
||||||
|
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
//reset timer in any case
|
//reset timer in any case
|
||||||
balloonCloseTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
balloonCloseTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||||
@@ -296,40 +303,42 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
//reset timer in any case
|
// reset timer in any case
|
||||||
balloonCloseTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
balloonCloseTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||||
|
|
||||||
//reset old popup, if we still have one
|
// reset old popup, if we still have one
|
||||||
Popup popup = CustomBalloon;
|
Popup popup = CustomBalloon;
|
||||||
if (popup != null)
|
if (popup == null)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
UIElement element = popup.Child;
|
UIElement element = popup.Child;
|
||||||
|
|
||||||
//announce closing
|
// announce closing
|
||||||
RoutedEventArgs eventArgs = RaiseBalloonClosingEvent(element, this);
|
RoutedEventArgs eventArgs = RaiseBalloonClosingEvent(element, this);
|
||||||
if (!eventArgs.Handled)
|
if (!eventArgs.Handled)
|
||||||
{
|
{
|
||||||
//if the event was handled, clear the reference to the popup,
|
// if the event was handled, clear the reference to the popup,
|
||||||
//but don't close it - the handling code has to manage this stuff now
|
// but don't close it - the handling code has to manage this stuff now
|
||||||
|
|
||||||
//close the popup
|
// close the popup
|
||||||
popup.IsOpen = false;
|
popup.IsOpen = false;
|
||||||
|
|
||||||
//remove the reference of the popup to the balloon in case we want to reuse
|
// remove the reference of the popup to the balloon in case we want to reuse
|
||||||
//the balloon (then added to a new popup)
|
// the balloon (then added to a new popup)
|
||||||
popup.Child = null;
|
popup.Child = null;
|
||||||
|
|
||||||
//reset attached property
|
// reset attached property
|
||||||
if (element != null) SetParentTaskbarIcon(element, null);
|
if (element != null) SetParentTaskbarIcon(element, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove custom balloon anyway
|
// remove custom balloon anyway
|
||||||
SetCustomBalloon(null);
|
SetCustomBalloon(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -340,7 +349,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (IsDisposed) return;
|
if (IsDisposed) return;
|
||||||
|
|
||||||
//switch to UI thread
|
// switch to UI thread
|
||||||
Action action = CloseBalloon;
|
Action action = CloseBalloon;
|
||||||
this.GetDispatcher().Invoke(action);
|
this.GetDispatcher().Invoke(action);
|
||||||
}
|
}
|
||||||
@@ -364,7 +373,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
case MouseEvent.MouseMove:
|
case MouseEvent.MouseMove:
|
||||||
RaiseTrayMouseMoveEvent();
|
RaiseTrayMouseMoveEvent();
|
||||||
//immediately return - there's nothing left to evaluate
|
// immediately return - there's nothing left to evaluate
|
||||||
return;
|
return;
|
||||||
case MouseEvent.IconRightMouseDown:
|
case MouseEvent.IconRightMouseDown:
|
||||||
RaiseTrayRightMouseDownEvent();
|
RaiseTrayRightMouseDownEvent();
|
||||||
@@ -385,24 +394,24 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
RaiseTrayMiddleMouseUpEvent();
|
RaiseTrayMiddleMouseUpEvent();
|
||||||
break;
|
break;
|
||||||
case MouseEvent.IconDoubleClick:
|
case MouseEvent.IconDoubleClick:
|
||||||
//cancel single click timer
|
// cancel single click timer
|
||||||
singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||||
//bubble event
|
// bubble event
|
||||||
RaiseTrayMouseDoubleClickEvent();
|
RaiseTrayMouseDoubleClickEvent();
|
||||||
break;
|
break;
|
||||||
case MouseEvent.BalloonToolTipClicked:
|
case MouseEvent.BalloonToolTipClicked:
|
||||||
RaiseTrayBalloonTipClickedEvent();
|
RaiseTrayBalloonTipClickedEvent();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me);
|
throw new ArgumentOutOfRangeException(nameof(me), "Missing handler for mouse event flag: " + me);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//get mouse coordinates
|
// get mouse coordinates
|
||||||
Point cursorPosition = new Point();
|
Point cursorPosition = new Point();
|
||||||
if (messageSink.Version == NotifyIconVersion.Vista)
|
if (messageSink.Version == NotifyIconVersion.Vista)
|
||||||
{
|
{
|
||||||
//physical cursor position is supported for Vista and above
|
// physical cursor position is supported for Vista and above
|
||||||
WinApi.GetPhysicalCursorPos(ref cursorPosition);
|
WinApi.GetPhysicalCursorPos(ref cursorPosition);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -414,12 +423,12 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
bool isLeftClickCommandInvoked = false;
|
bool isLeftClickCommandInvoked = false;
|
||||||
|
|
||||||
//show popup, if requested
|
// show popup, if requested
|
||||||
if (me.IsMatch(PopupActivation))
|
if (me.IsMatch(PopupActivation))
|
||||||
{
|
{
|
||||||
if (me == MouseEvent.IconLeftMouseUp)
|
if (me == MouseEvent.IconLeftMouseUp)
|
||||||
{
|
{
|
||||||
//show popup once we are sure it's not a double click
|
// show popup once we are sure it's not a double click
|
||||||
singleClickTimerAction = () =>
|
singleClickTimerAction = () =>
|
||||||
{
|
{
|
||||||
LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
|
LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
|
||||||
@@ -430,18 +439,18 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//show popup immediately
|
// show popup immediately
|
||||||
ShowTrayPopup(cursorPosition);
|
ShowTrayPopup(cursorPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//show context menu, if requested
|
// show context menu, if requested
|
||||||
if (me.IsMatch(MenuActivation))
|
if (me.IsMatch(MenuActivation))
|
||||||
{
|
{
|
||||||
if (me == MouseEvent.IconLeftMouseUp)
|
if (me == MouseEvent.IconLeftMouseUp)
|
||||||
{
|
{
|
||||||
//show context menu once we are sure it's not a double click
|
// show context menu once we are sure it's not a double click
|
||||||
singleClickTimerAction = () =>
|
singleClickTimerAction = () =>
|
||||||
{
|
{
|
||||||
LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
|
LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
|
||||||
@@ -452,15 +461,15 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//show context menu immediately
|
// show context menu immediately
|
||||||
ShowContextMenu(cursorPosition);
|
ShowContextMenu(cursorPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//make sure the left click command is invoked on mouse clicks
|
// make sure the left click command is invoked on mouse clicks
|
||||||
if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked)
|
if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked)
|
||||||
{
|
{
|
||||||
//show context menu once we are sure it's not a double click
|
// show context menu once we are sure it's not a double click
|
||||||
singleClickTimerAction =
|
singleClickTimerAction =
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
@@ -481,14 +490,14 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <param name="visible">Whether to show or hide the tooltip.</param>
|
/// <param name="visible">Whether to show or hide the tooltip.</param>
|
||||||
private void OnToolTipChange(bool visible)
|
private void OnToolTipChange(bool visible)
|
||||||
{
|
{
|
||||||
//if we don't have a tooltip, there's nothing to do here...
|
// if we don't have a tooltip, there's nothing to do here...
|
||||||
if (TrayToolTipResolved == null) return;
|
if (TrayToolTipResolved == null) return;
|
||||||
|
|
||||||
if (visible)
|
if (visible)
|
||||||
{
|
{
|
||||||
if (IsPopupOpen)
|
if (IsPopupOpen)
|
||||||
{
|
{
|
||||||
//ignore if we are already displaying something down there
|
// ignore if we are already displaying something down there
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,10 +506,10 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
TrayToolTipResolved.IsOpen = true;
|
TrayToolTipResolved.IsOpen = true;
|
||||||
|
|
||||||
//raise attached event first
|
// raise attached event first
|
||||||
if (TrayToolTip != null) RaiseToolTipOpenedEvent(TrayToolTip);
|
if (TrayToolTip != null) RaiseToolTipOpenedEvent(TrayToolTip);
|
||||||
|
|
||||||
//bubble routed event
|
// bubble routed event
|
||||||
RaiseTrayToolTipOpenEvent();
|
RaiseTrayToolTipOpenEvent();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -508,12 +517,12 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
var args = RaisePreviewTrayToolTipCloseEvent();
|
var args = RaisePreviewTrayToolTipCloseEvent();
|
||||||
if (args.Handled) return;
|
if (args.Handled) return;
|
||||||
|
|
||||||
//raise attached event first
|
// raise attached event first
|
||||||
if (TrayToolTip != null) RaiseToolTipCloseEvent(TrayToolTip);
|
if (TrayToolTip != null) RaiseToolTipCloseEvent(TrayToolTip);
|
||||||
|
|
||||||
TrayToolTipResolved.IsOpen = false;
|
TrayToolTipResolved.IsOpen = false;
|
||||||
|
|
||||||
//bubble event
|
// bubble event
|
||||||
RaiseTrayToolTipCloseEvent();
|
RaiseTrayToolTipCloseEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -534,44 +543,46 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// property which prevents this issue.</remarks>
|
/// property which prevents this issue.</remarks>
|
||||||
private void CreateCustomToolTip()
|
private void CreateCustomToolTip()
|
||||||
{
|
{
|
||||||
//check if the item itself is a tooltip
|
// check if the item itself is a tooltip
|
||||||
ToolTip tt = TrayToolTip as ToolTip;
|
ToolTip tt = TrayToolTip as ToolTip;
|
||||||
|
|
||||||
if (tt == null && TrayToolTip != null)
|
if (tt == null && TrayToolTip != null)
|
||||||
{
|
{
|
||||||
//create an invisible wrapper tooltip that hosts the UIElement
|
// create an invisible wrapper tooltip that hosts the UIElement
|
||||||
tt = new ToolTip();
|
tt = new ToolTip
|
||||||
tt.Placement = PlacementMode.Mouse;
|
|
||||||
|
|
||||||
//do *not* set the placement target, as it causes the popup to become hidden if the
|
|
||||||
//TaskbarIcon's parent is hidden, too. At runtime, the parent can be resolved through
|
|
||||||
//the ParentTaskbarIcon attached dependency property:
|
|
||||||
//tt.PlacementTarget = 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 = TrayToolTip;
|
|
||||||
}
|
|
||||||
else if (tt == null && !String.IsNullOrEmpty(ToolTipText))
|
|
||||||
{
|
{
|
||||||
//create a simple tooltip for the ToolTipText string
|
Placement = PlacementMode.Mouse,
|
||||||
tt = new ToolTip();
|
// do *not* set the placement target, as it causes the popup to become hidden if the
|
||||||
tt.Content = ToolTipText;
|
// TaskbarIcon's parent is hidden, too. At runtime, the parent can be resolved through
|
||||||
|
// the ParentTaskbarIcon attached dependency property:
|
||||||
|
// PlacementTarget = this;
|
||||||
|
|
||||||
|
// make sure the tooltip is invisible
|
||||||
|
HasDropShadow = false,
|
||||||
|
BorderThickness = new Thickness(0),
|
||||||
|
Background = System.Windows.Media.Brushes.Transparent,
|
||||||
|
// setting the
|
||||||
|
StaysOpen = true,
|
||||||
|
Content = TrayToolTip
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (tt == null && !string.IsNullOrEmpty(ToolTipText))
|
||||||
|
{
|
||||||
|
// create a simple tooltip for the ToolTipText string
|
||||||
|
tt = new ToolTip
|
||||||
|
{
|
||||||
|
Content = ToolTipText
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//the tooltip explicitly gets the DataContext of this instance.
|
// the tooltip explicitly gets the DataContext of this instance.
|
||||||
//If there is no DataContext, the TaskbarIcon assigns itself
|
// If there is no DataContext, the TaskbarIcon assigns itself
|
||||||
if (tt != null)
|
if (tt != null)
|
||||||
{
|
{
|
||||||
UpdateDataContext(tt, null, DataContext);
|
UpdateDataContext(tt, null, DataContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
//store a reference to the used tooltip
|
// store a reference to the used tooltip
|
||||||
SetTrayToolTipResolved(tt);
|
SetTrayToolTipResolved(tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,17 +598,17 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
if (messageSink.Version == NotifyIconVersion.Vista)
|
if (messageSink.Version == NotifyIconVersion.Vista)
|
||||||
{
|
{
|
||||||
//we need to set a tooltip text to get tooltip events from the
|
// we need to set a tooltip text to get tooltip events from the
|
||||||
//taskbar icon
|
// taskbar icon
|
||||||
if (String.IsNullOrEmpty(iconData.ToolTipText) && TrayToolTipResolved != null)
|
if (string.IsNullOrEmpty(iconData.ToolTipText) && TrayToolTipResolved != null)
|
||||||
{
|
{
|
||||||
//if we have not tooltip text but a custom tooltip, we
|
// 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)
|
// need to set a dummy value (we're displaying the ToolTip control, not the string)
|
||||||
iconData.ToolTipText = "ToolTip";
|
iconData.ToolTipText = "ToolTip";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the tooltip text
|
// update the tooltip text
|
||||||
Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags);
|
Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,114 +631,115 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// property which prevents this issue.</remarks>
|
/// property which prevents this issue.</remarks>
|
||||||
private void CreatePopup()
|
private void CreatePopup()
|
||||||
{
|
{
|
||||||
//check if the item itself is a popup
|
// check if the item itself is a popup
|
||||||
Popup popup = TrayPopup as Popup;
|
Popup popup = TrayPopup as Popup;
|
||||||
|
|
||||||
if (popup == null && TrayPopup != null)
|
if (popup == null && TrayPopup != null)
|
||||||
{
|
{
|
||||||
//create an invisible popup that hosts the UIElement
|
// create an invisible popup that hosts the UIElement
|
||||||
popup = new Popup();
|
popup = new Popup
|
||||||
popup.AllowsTransparency = true;
|
{
|
||||||
|
AllowsTransparency = true,
|
||||||
|
// don't animate by default - developers can use attached events or override
|
||||||
|
PopupAnimation = PopupAnimation.None,
|
||||||
|
// the CreateRootPopup method outputs binding errors in the debug window because
|
||||||
|
// it tries to bind to "Popup-specific" properties in case they are provided by the child.
|
||||||
|
// We don't need that so just assign the control as the child.
|
||||||
|
Child = TrayPopup,
|
||||||
|
// do *not* set the placement target, as it causes the popup to become hidden if the
|
||||||
|
// TaskbarIcon's parent is hidden, too. At runtime, the parent can be resolved through
|
||||||
|
// the ParentTaskbarIcon attached dependency property:
|
||||||
|
// PlacementTarget = this;
|
||||||
|
|
||||||
//don't animate by default - devs can use attached
|
Placement = PlacementMode.AbsolutePoint,
|
||||||
//events or override
|
StaysOpen = false
|
||||||
popup.PopupAnimation = PopupAnimation.None;
|
};
|
||||||
|
|
||||||
//the CreateRootPopup method outputs binding errors in the debug window because
|
|
||||||
//it tries to bind to "Popup-specific" properties in case they are provided by the child.
|
|
||||||
//We don't need that so just assign the control as the child.
|
|
||||||
popup.Child = TrayPopup;
|
|
||||||
|
|
||||||
//do *not* set the placement target, as it causes the popup to become hidden if the
|
|
||||||
//TaskbarIcon's parent is hidden, too. At runtime, the parent can be resolved through
|
|
||||||
//the ParentTaskbarIcon attached dependency property:
|
|
||||||
//popup.PlacementTarget = this;
|
|
||||||
|
|
||||||
popup.Placement = PlacementMode.AbsolutePoint;
|
|
||||||
popup.StaysOpen = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//the popup explicitly gets the DataContext of this instance.
|
// the popup explicitly gets the DataContext of this instance.
|
||||||
//If there is no DataContext, the TaskbarIcon assigns itself
|
// If there is no DataContext, the TaskbarIcon assigns itself
|
||||||
if (popup != null)
|
if (popup != null)
|
||||||
{
|
{
|
||||||
UpdateDataContext(popup, null, DataContext);
|
UpdateDataContext(popup, null, DataContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
//store a reference to the used tooltip
|
// store a reference to the used tooltip
|
||||||
SetTrayPopupResolved(popup);
|
SetTrayPopupResolved(popup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Displays the <see cref="TrayPopup"/> control if
|
/// Displays the <see cref="TrayPopup"/> control if it was set.
|
||||||
/// it was set.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ShowTrayPopup(Point cursorPosition)
|
private void ShowTrayPopup(Point cursorPosition)
|
||||||
{
|
{
|
||||||
if (IsDisposed) return;
|
if (IsDisposed) return;
|
||||||
|
|
||||||
//raise preview event no matter whether popup is currently set
|
// raise preview event no matter whether popup is currently set
|
||||||
//or not (enables client to set it on demand)
|
// or not (enables client to set it on demand)
|
||||||
var args = RaisePreviewTrayPopupOpenEvent();
|
var args = RaisePreviewTrayPopupOpenEvent();
|
||||||
if (args.Handled) return;
|
if (args.Handled) return;
|
||||||
|
|
||||||
if (TrayPopup != null)
|
if (TrayPopup == null)
|
||||||
{
|
{
|
||||||
//use absolute position, but place the popup centered above the icon
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use absolute position, but place the popup centered above the icon
|
||||||
TrayPopupResolved.Placement = PlacementMode.AbsolutePoint;
|
TrayPopupResolved.Placement = PlacementMode.AbsolutePoint;
|
||||||
TrayPopupResolved.HorizontalOffset = cursorPosition.X;
|
TrayPopupResolved.HorizontalOffset = cursorPosition.X;
|
||||||
TrayPopupResolved.VerticalOffset = cursorPosition.Y;
|
TrayPopupResolved.VerticalOffset = cursorPosition.Y;
|
||||||
|
|
||||||
//open popup
|
// open popup
|
||||||
TrayPopupResolved.IsOpen = true;
|
TrayPopupResolved.IsOpen = true;
|
||||||
|
|
||||||
IntPtr handle = IntPtr.Zero;
|
IntPtr handle = IntPtr.Zero;
|
||||||
if (TrayPopupResolved.Child != null)
|
if (TrayPopupResolved.Child != null)
|
||||||
{
|
{
|
||||||
//try to get a handle on the popup itself (via its child)
|
// try to get a handle on the popup itself (via its child)
|
||||||
HwndSource source = (HwndSource) PresentationSource.FromVisual(TrayPopupResolved.Child);
|
HwndSource source = (HwndSource)PresentationSource.FromVisual(TrayPopupResolved.Child);
|
||||||
if (source != null) handle = source.Handle;
|
if (source != null) handle = source.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if we don't have a handle for the popup, fall back to the message sink
|
// if we don't have a handle for the popup, fall back to the message sink
|
||||||
if (handle == IntPtr.Zero) handle = messageSink.MessageWindowHandle;
|
if (handle == IntPtr.Zero) handle = messageSink.MessageWindowHandle;
|
||||||
|
|
||||||
//activate either popup or message sink to track deactivation.
|
// activate either popup or message sink to track deactivation.
|
||||||
//otherwise, the popup does not close if the user clicks somewhere else
|
// otherwise, the popup does not close if the user clicks somewhere else
|
||||||
WinApi.SetForegroundWindow(handle);
|
WinApi.SetForegroundWindow(handle);
|
||||||
|
|
||||||
//raise attached event - item should never be null unless developers
|
// raise attached event - item should never be null unless developers
|
||||||
//changed the CustomPopup directly...
|
// changed the CustomPopup directly...
|
||||||
if (TrayPopup != null) RaisePopupOpenedEvent(TrayPopup);
|
if (TrayPopup != null) RaisePopupOpenedEvent(TrayPopup);
|
||||||
|
|
||||||
//bubble routed event
|
// bubble routed event
|
||||||
RaiseTrayPopupOpenEvent();
|
RaiseTrayPopupOpenEvent();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Context Menu
|
#region Context Menu
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Displays the <see cref="ContextMenu"/> if
|
/// Displays the <see cref="ContextMenu"/> if it was set.
|
||||||
/// it was set.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ShowContextMenu(Point cursorPosition)
|
private void ShowContextMenu(Point cursorPosition)
|
||||||
{
|
{
|
||||||
if (IsDisposed) return;
|
if (IsDisposed) return;
|
||||||
|
|
||||||
//raise preview event no matter whether context menu is currently set
|
// raise preview event no matter whether context menu is currently set
|
||||||
//or not (enables client to set it on demand)
|
// or not (enables client to set it on demand)
|
||||||
var args = RaisePreviewTrayContextMenuOpenEvent();
|
var args = RaisePreviewTrayContextMenuOpenEvent();
|
||||||
if (args.Handled) return;
|
if (args.Handled) return;
|
||||||
|
|
||||||
if (ContextMenu != null)
|
if (ContextMenu == null)
|
||||||
{
|
{
|
||||||
//use absolute positioning. We need to set the coordinates, or a delayed opening
|
return;
|
||||||
//(e.g. when left-clicked) opens the context menu at the wrong place if the mouse
|
}
|
||||||
//is moved!
|
|
||||||
|
// use absolute positioning. We need to set the coordinates, or a delayed opening
|
||||||
|
// (e.g. when left-clicked) opens the context menu at the wrong place if the mouse
|
||||||
|
// is moved!
|
||||||
ContextMenu.Placement = PlacementMode.AbsolutePoint;
|
ContextMenu.Placement = PlacementMode.AbsolutePoint;
|
||||||
ContextMenu.HorizontalOffset = cursorPosition.X;
|
ContextMenu.HorizontalOffset = cursorPosition.X;
|
||||||
ContextMenu.VerticalOffset = cursorPosition.Y;
|
ContextMenu.VerticalOffset = cursorPosition.Y;
|
||||||
@@ -735,25 +747,24 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
IntPtr handle = IntPtr.Zero;
|
IntPtr handle = IntPtr.Zero;
|
||||||
|
|
||||||
//try to get a handle on the context itself
|
// try to get a handle on the context itself
|
||||||
HwndSource source = (HwndSource) PresentationSource.FromVisual(ContextMenu);
|
HwndSource source = (HwndSource)PresentationSource.FromVisual(ContextMenu);
|
||||||
if (source != null)
|
if (source != null)
|
||||||
{
|
{
|
||||||
handle = source.Handle;
|
handle = source.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if we don't have a handle for the popup, fall back to the message sink
|
// if we don't have a handle for the popup, fall back to the message sink
|
||||||
if (handle == IntPtr.Zero) handle = messageSink.MessageWindowHandle;
|
if (handle == IntPtr.Zero) handle = messageSink.MessageWindowHandle;
|
||||||
|
|
||||||
//activate the context menu or the message window to track deactivation - otherwise, the context menu
|
// activate the context menu or the message window to track deactivation - otherwise, the context menu
|
||||||
//does not close if the user clicks somewhere else. With the message window
|
// does not close if the user clicks somewhere else. With the message window
|
||||||
//fallback, the context menu can't receive keyboard events - should not happen though
|
// fallback, the context menu can't receive keyboard events - should not happen though
|
||||||
WinApi.SetForegroundWindow(handle);
|
WinApi.SetForegroundWindow(handle);
|
||||||
|
|
||||||
//bubble event
|
// bubble event
|
||||||
RaiseTrayContextMenuOpenEvent();
|
RaiseTrayContextMenuOpenEvent();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -786,7 +797,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <param name="symbol">A symbol that indicates the severity.</param>
|
/// <param name="symbol">A symbol that indicates the severity.</param>
|
||||||
public void ShowBalloonTip(string title, string message, BalloonIcon symbol)
|
public void ShowBalloonTip(string title, string message, BalloonIcon symbol)
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
ShowBalloonTip(title, message, symbol.GetBalloonFlag(), IntPtr.Zero);
|
ShowBalloonTip(title, message, symbol.GetBalloonFlag(), IntPtr.Zero);
|
||||||
}
|
}
|
||||||
@@ -804,14 +815,17 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// is a null reference.</exception>
|
/// is a null reference.</exception>
|
||||||
public void ShowBalloonTip(string title, string message, Icon customIcon, bool largeIcon = false)
|
public void ShowBalloonTip(string title, string message, Icon customIcon, bool largeIcon = false)
|
||||||
{
|
{
|
||||||
if (customIcon == null) throw new ArgumentNullException("customIcon");
|
if (customIcon == null) throw new ArgumentNullException(nameof(customIcon));
|
||||||
|
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
var flags = BalloonFlags.User;
|
var flags = BalloonFlags.User;
|
||||||
|
|
||||||
if (largeIcon)
|
if (largeIcon)
|
||||||
|
{
|
||||||
|
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
|
||||||
flags |= BalloonFlags.LargeIcon;
|
flags |= BalloonFlags.LargeIcon;
|
||||||
|
}
|
||||||
|
|
||||||
ShowBalloonTip(title, message, flags, customIcon.Handle);
|
ShowBalloonTip(title, message, flags, customIcon.Handle);
|
||||||
}
|
}
|
||||||
@@ -831,8 +845,8 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
EnsureNotDisposed();
|
EnsureNotDisposed();
|
||||||
|
|
||||||
iconData.BalloonText = message ?? String.Empty;
|
iconData.BalloonText = message ?? string.Empty;
|
||||||
iconData.BalloonTitle = title ?? String.Empty;
|
iconData.BalloonTitle = title ?? string.Empty;
|
||||||
|
|
||||||
iconData.BalloonFlags = flags;
|
iconData.BalloonFlags = flags;
|
||||||
iconData.CustomBalloonIconHandle = balloonIconHandle;
|
iconData.CustomBalloonIconHandle = balloonIconHandle;
|
||||||
@@ -847,8 +861,8 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
EnsureNotDisposed();
|
EnsureNotDisposed();
|
||||||
|
|
||||||
//reset balloon by just setting the info to an empty string
|
// reset balloon by just setting the info to an empty string
|
||||||
iconData.BalloonText = iconData.BalloonTitle = String.Empty;
|
iconData.BalloonText = iconData.BalloonTitle = string.Empty;
|
||||||
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info);
|
Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,14 +879,14 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
{
|
{
|
||||||
if (IsDisposed) return;
|
if (IsDisposed) return;
|
||||||
|
|
||||||
//run action
|
// run action
|
||||||
Action action = singleClickTimerAction;
|
Action action = singleClickTimerAction;
|
||||||
if (action != null)
|
if (action != null)
|
||||||
{
|
{
|
||||||
//cleanup action
|
// cleanup action
|
||||||
singleClickTimerAction = null;
|
singleClickTimerAction = null;
|
||||||
|
|
||||||
//switch to UI thread
|
// switch to UI thread
|
||||||
this.GetDispatcher().Invoke(action);
|
this.GetDispatcher().Invoke(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -886,18 +900,18 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// </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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -928,10 +942,13 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void CreateTaskbarIcon()
|
private void CreateTaskbarIcon()
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
if (!IsTaskbarIconCreated)
|
if (IsTaskbarIconCreated)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const IconDataMembers members = IconDataMembers.Message
|
const IconDataMembers members = IconDataMembers.Message
|
||||||
| IconDataMembers.Icon
|
| IconDataMembers.Icon
|
||||||
| IconDataMembers.Tip;
|
| IconDataMembers.Tip;
|
||||||
@@ -940,38 +957,39 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members);
|
var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members);
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
//couldn't create the icon - we can assume this is because explorer is not running (yet!)
|
// couldn't create the icon - we can assume this is because explorer is not running (yet!)
|
||||||
//-> try a bit later again rather than throwing an exception. Typically, if the windows
|
// -> try a bit later again rather than throwing an exception. Typically, if the windows
|
||||||
// shell is being loaded later, this method is being reinvoked from OnTaskbarCreated
|
// shell is being loaded later, this method is being re-invoked from OnTaskbarCreated
|
||||||
// (we could also retry after a delay, but that's currently YAGNI)
|
// (we could also retry after a delay, but that's currently YAGNI)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//set to most recent version
|
//set to most recent version
|
||||||
SetVersion();
|
SetVersion();
|
||||||
messageSink.Version = (NotifyIconVersion) iconData.VersionOrTimeout;
|
messageSink.Version = (NotifyIconVersion)iconData.VersionOrTimeout;
|
||||||
|
|
||||||
IsTaskbarIconCreated = true;
|
IsTaskbarIconCreated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Closes the taskbar icon if required.
|
/// Closes the taskbar icon if required.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void RemoveTaskbarIcon()
|
private void RemoveTaskbarIcon()
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
//make sure we didn't schedule a creation
|
// make sure we didn't schedule a creation
|
||||||
|
|
||||||
if (IsTaskbarIconCreated)
|
if (!IsTaskbarIconCreated)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Util.WriteIconData(ref iconData, NotifyCommand.Delete, IconDataMembers.Message);
|
Util.WriteIconData(ref iconData, NotifyCommand.Delete, IconDataMembers.Message);
|
||||||
IsTaskbarIconCreated = false;
|
IsTaskbarIconCreated = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1010,8 +1028,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// method does not get called. This gives this base class the
|
/// method does not get called. This gives this base class the
|
||||||
/// opportunity to finalize.
|
/// opportunity to finalize.
|
||||||
/// <para>
|
/// <para>
|
||||||
/// Important: Do not provide destructors in types derived from
|
/// Important: Do not provide destructor in types derived from this class.
|
||||||
/// this class.
|
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
~TaskbarIcon()
|
~TaskbarIcon()
|
||||||
@@ -1031,7 +1048,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
|
||||||
// This object will be cleaned up by the Dispose method.
|
// This object will be cleaned up by the Dispose method.
|
||||||
// Therefore, you should call GC.SupressFinalize to
|
// Therefore, you should call GC.SuppressFinalize to
|
||||||
// take this object off the finalization queue
|
// take this object off the finalization queue
|
||||||
// and prevent finalization code for this object
|
// and prevent finalization code for this object
|
||||||
// from executing a second time.
|
// from executing a second time.
|
||||||
@@ -1056,27 +1073,27 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// 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;
|
||||||
|
|
||||||
lock (this)
|
lock (lockObject)
|
||||||
{
|
{
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
|
|
||||||
//deregister application event listener
|
// de-register application event listener
|
||||||
if (Application.Current != null)
|
if (Application.Current != null)
|
||||||
{
|
{
|
||||||
Application.Current.Exit -= OnExit;
|
Application.Current.Exit -= OnExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
//stop timers
|
// stop timers
|
||||||
singleClickTimer.Dispose();
|
singleClickTimer.Dispose();
|
||||||
balloonCloseTimer.Dispose();
|
balloonCloseTimer.Dispose();
|
||||||
|
|
||||||
//dispose message sink
|
// dispose message sink
|
||||||
messageSink.Dispose();
|
messageSink.Dispose();
|
||||||
|
|
||||||
//remove icon
|
// remove icon
|
||||||
RemoveTaskbarIcon();
|
RemoveTaskbarIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
if (streamInfo == null)
|
if (streamInfo == null)
|
||||||
{
|
{
|
||||||
string msg = "The supplied image source '{0}' could not be resolved.";
|
string msg = "The supplied image source '{0}' could not be resolved.";
|
||||||
msg = String.Format(msg, imageSource);
|
msg = string.Format(msg, imageSource);
|
||||||
throw new ArgumentException(msg);
|
throw new ArgumentException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a dispatcher for multi-threaded scenarios
|
/// Returns a dispatcher for multi-threaded scenarios
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns>Dispatcher</returns>
|
||||||
internal static Dispatcher GetDispatcher(this DispatcherObject source)
|
internal static Dispatcher GetDispatcher(this DispatcherObject source)
|
||||||
{
|
{
|
||||||
//use the application's dispatcher by default
|
//use the application's dispatcher by default
|
||||||
@@ -286,7 +286,7 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
//fallback for WinForms environments
|
//fallback for WinForms environments
|
||||||
if (source.Dispatcher != null) return source.Dispatcher;
|
if (source.Dispatcher != null) return source.Dispatcher;
|
||||||
|
|
||||||
//ultimatively use the thread's dispatcher
|
// ultimately use the thread's dispatcher
|
||||||
return Dispatcher.CurrentDispatcher;
|
return Dispatcher.CurrentDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Windows;
|
|
||||||
using Hardcodet.Wpf.TaskbarNotification;
|
|
||||||
|
|
||||||
namespace Samples
|
namespace Samples
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace Samples.Commands
|
|||||||
/// </param>
|
/// </param>
|
||||||
public virtual bool CanExecute(object parameter)
|
public virtual bool CanExecute(object parameter)
|
||||||
{
|
{
|
||||||
return IsDesignMode ? false : true;
|
return !IsDesignMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,12 +82,12 @@ namespace Samples.Commands
|
|||||||
/// Resolves the window that owns the TaskbarIcon class.
|
/// Resolves the window that owns the TaskbarIcon class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="commandParameter"></param>
|
/// <param name="commandParameter"></param>
|
||||||
/// <returns></returns>
|
/// <returns>Window</returns>
|
||||||
protected Window GetTaskbarWindow(object commandParameter)
|
protected Window GetTaskbarWindow(object commandParameter)
|
||||||
{
|
{
|
||||||
if (IsDesignMode) return null;
|
if (IsDesignMode) return null;
|
||||||
|
|
||||||
//get the showcase window off the taskbaricon
|
// get the showcase window off the taskbar icon
|
||||||
var tb = commandParameter as TaskbarIcon;
|
var tb = commandParameter as TaskbarIcon;
|
||||||
return tb == null ? null : TryFindParent<Window>(tb);
|
return tb == null ? null : TryFindParent<Window>(tb);
|
||||||
}
|
}
|
||||||
@@ -97,14 +97,13 @@ namespace Samples.Commands
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds a parent of a given item on the visual tree.
|
/// Finds a parent of a given item on the visual tree.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of the queried item.</typeparam>
|
/// <typeparam name="TParent">The type of the queried item.</typeparam>
|
||||||
/// <param name="child">A direct or indirect child of the
|
/// <param name="child">A direct or indirect child of the
|
||||||
/// queried item.</param>
|
/// queried item.</param>
|
||||||
/// <returns>The first parent item that matches the submitted
|
/// <returns>The first parent item that matches the submitted
|
||||||
/// type parameter. If not matching item can be found, a null
|
/// type parameter. If not matching item can be found, a null
|
||||||
/// reference is being returned.</returns>
|
/// reference is being returned.</returns>
|
||||||
public static T TryFindParent<T>(DependencyObject child)
|
public static TParent TryFindParent<TParent>(DependencyObject child) where TParent : DependencyObject
|
||||||
where T : DependencyObject
|
|
||||||
{
|
{
|
||||||
//get parent item
|
//get parent item
|
||||||
DependencyObject parentObject = GetParentObject(child);
|
DependencyObject parentObject = GetParentObject(child);
|
||||||
@@ -113,16 +112,13 @@ namespace Samples.Commands
|
|||||||
if (parentObject == null) return null;
|
if (parentObject == null) return null;
|
||||||
|
|
||||||
//check if the parent matches the type we're looking for
|
//check if the parent matches the type we're looking for
|
||||||
T parent = parentObject as T;
|
if (parentObject is TParent parent)
|
||||||
if (parent != null)
|
|
||||||
{
|
{
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//use recursion to proceed with next level
|
//use recursion to proceed with next level
|
||||||
return TryFindParent<T>(parentObject);
|
return TryFindParent<TParent>(parentObject);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -137,15 +133,14 @@ namespace Samples.Commands
|
|||||||
public static DependencyObject GetParentObject(DependencyObject child)
|
public static DependencyObject GetParentObject(DependencyObject child)
|
||||||
{
|
{
|
||||||
if (child == null) return null;
|
if (child == null) return null;
|
||||||
ContentElement contentElement = child as ContentElement;
|
|
||||||
|
|
||||||
if (contentElement != null)
|
if (child is ContentElement contentElement)
|
||||||
{
|
{
|
||||||
DependencyObject parent = ContentOperations.GetParent(contentElement);
|
DependencyObject parent = ContentOperations.GetParent(contentElement);
|
||||||
if (parent != null) return parent;
|
if (parent != null) return parent;
|
||||||
|
|
||||||
FrameworkContentElement fce = contentElement as FrameworkContentElement;
|
FrameworkContentElement fce = contentElement as FrameworkContentElement;
|
||||||
return fce != null ? fce.Parent : null;
|
return fce?.Parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if it's not a ContentElement, rely on VisualTreeHelper
|
//if it's not a ContentElement, rely on VisualTreeHelper
|
||||||
|
|||||||
@@ -82,17 +82,19 @@ namespace Samples
|
|||||||
ShowDialog(new DataBoundToolTipWindow());
|
ShowDialog(new DataBoundToolTipWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnMvvm_Click(object sender, System.Windows.RoutedEventArgs e)
|
private void btnMvvm_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ShowDialog(new MvvmSampleWindow());
|
ShowDialog(new MvvmSampleWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnMainSample_Click(object sender, RoutedEventArgs e)
|
private void btnMainSample_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var sampleWindow = new ShowcaseWindow();
|
var sampleWindow = new ShowcaseWindow
|
||||||
|
{
|
||||||
|
Owner = this,
|
||||||
|
WindowStartupLocation = WindowStartupLocation.CenterScreen
|
||||||
|
};
|
||||||
|
|
||||||
sampleWindow.Owner = this;
|
|
||||||
sampleWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
||||||
sampleWindow.ShowDialog();
|
sampleWindow.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Runtime.InteropServices;
|
||||||
using System.Resources;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
|||||||
@@ -1,18 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
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.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using Hardcodet.Wpf.TaskbarNotification;
|
using Hardcodet.Wpf.TaskbarNotification;
|
||||||
|
|
||||||
namespace Samples
|
namespace Samples
|
||||||
@@ -30,10 +20,10 @@ namespace Samples
|
|||||||
/// Description
|
/// Description
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty BalloonTextProperty =
|
public static readonly DependencyProperty BalloonTextProperty =
|
||||||
DependencyProperty.Register("BalloonText",
|
DependencyProperty.Register(nameof(BalloonText),
|
||||||
typeof (string),
|
typeof (string),
|
||||||
typeof (FancyBalloon),
|
typeof (FancyBalloon),
|
||||||
new FrameworkPropertyMetadata(""));
|
new FrameworkPropertyMetadata(string.Empty));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A property wrapper for the <see cref="BalloonTextProperty"/>
|
/// A property wrapper for the <see cref="BalloonTextProperty"/>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Samples
|
|||||||
/// The number of clicks on the popup button.
|
/// The number of clicks on the popup button.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty ClickCountProperty =
|
public static readonly DependencyProperty ClickCountProperty =
|
||||||
DependencyProperty.Register("ClickCount",
|
DependencyProperty.Register(nameof(ClickCount),
|
||||||
typeof (int),
|
typeof (int),
|
||||||
typeof (FancyPopup),
|
typeof (FancyPopup),
|
||||||
new FrameworkPropertyMetadata(0));
|
new FrameworkPropertyMetadata(0));
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using Hardcodet.Wpf.TaskbarNotification;
|
|
||||||
|
|
||||||
namespace Samples
|
namespace Samples
|
||||||
{
|
{
|
||||||
@@ -25,10 +13,10 @@ namespace Samples
|
|||||||
/// The tooltip details.
|
/// The tooltip details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty InfoTextProperty =
|
public static readonly DependencyProperty InfoTextProperty =
|
||||||
DependencyProperty.Register("InfoText",
|
DependencyProperty.Register(nameof(InfoText),
|
||||||
typeof (string),
|
typeof (string),
|
||||||
typeof (FancyToolTip),
|
typeof (FancyToolTip),
|
||||||
new FrameworkPropertyMetadata(""));
|
new FrameworkPropertyMetadata(string.Empty));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A property wrapper for the <see cref="InfoTextProperty"/>
|
/// A property wrapper for the <see cref="InfoTextProperty"/>
|
||||||
@@ -45,7 +33,7 @@ namespace Samples
|
|||||||
|
|
||||||
public FancyToolTip()
|
public FancyToolTip()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,4 @@
|
|||||||
using System;
|
using System.Windows.Controls;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Samples
|
namespace Samples
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.ToolTips
|
namespace Samples.Tutorials.ToolTips
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
using System;
|
using System.Windows.Controls;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.ToolTips
|
namespace Samples.Tutorials.ToolTips
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.ToolTips
|
namespace Samples.Tutorials.ToolTips
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.Popups
|
namespace Samples.Tutorials.Popups
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using System.Windows;
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Input;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.ContextMenus
|
namespace Samples.Tutorials.ContextMenus
|
||||||
{
|
{
|
||||||
@@ -24,12 +21,12 @@ namespace Samples.Tutorials.ContextMenus
|
|||||||
base.OnClosing(e);
|
base.OnClosing(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MyNotifyIcon_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
|
private void MyNotifyIcon_TrayContextMenuOpen(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
OpenEventCounter.Text = (int.Parse(OpenEventCounter.Text) + 1).ToString();
|
OpenEventCounter.Text = (int.Parse(OpenEventCounter.Text) + 1).ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MyNotifyIcon_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
|
private void MyNotifyIcon_PreviewTrayContextMenuOpen(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
//marking the event as handled suppresses the context menu
|
//marking the event as handled suppresses the context menu
|
||||||
e.Handled = (bool) SuppressContextMenu.IsChecked;
|
e.Handled = (bool) SuppressContextMenu.IsChecked;
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using Hardcodet.Wpf.TaskbarNotification;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.Balloons
|
namespace Samples.Tutorials.Balloons
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.Commands
|
namespace Samples.Tutorials.Commands
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Samples.Tutorials.MvvmSample
|
|||||||
{
|
{
|
||||||
public ClockPopup()
|
public ClockPopup()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace Windowless_Sample
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Simplistic delegate command for the demo.
|
||||||
|
/// </summary>
|
||||||
|
public class DelegateCommand : ICommand
|
||||||
|
{
|
||||||
|
public Action CommandAction { get; set; }
|
||||||
|
public Func<bool> CanExecuteFunc { get; set; }
|
||||||
|
|
||||||
|
public void Execute(object parameter)
|
||||||
|
{
|
||||||
|
CommandAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanExecute(object parameter)
|
||||||
|
{
|
||||||
|
return CanExecuteFunc == null || CanExecuteFunc();
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler CanExecuteChanged
|
||||||
|
{
|
||||||
|
add { CommandManager.RequerySuggested += value; }
|
||||||
|
remove { CommandManager.RequerySuggested -= value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Windowless_Sample
|
namespace Windowless_Sample
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Windowless_Sample
|
namespace Windowless_Sample
|
||||||
@@ -57,30 +56,4 @@ namespace Windowless_Sample
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Simplistic delegate command for the demo.
|
|
||||||
/// </summary>
|
|
||||||
public class DelegateCommand : ICommand
|
|
||||||
{
|
|
||||||
public Action CommandAction { get; set; }
|
|
||||||
public Func<bool> CanExecuteFunc { get; set; }
|
|
||||||
|
|
||||||
public void Execute(object parameter)
|
|
||||||
{
|
|
||||||
CommandAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CanExecute(object parameter)
|
|
||||||
{
|
|
||||||
return CanExecuteFunc == null || CanExecuteFunc();
|
|
||||||
}
|
|
||||||
|
|
||||||
public event EventHandler CanExecuteChanged
|
|
||||||
{
|
|
||||||
add { CommandManager.RequerySuggested += value; }
|
|
||||||
remove { CommandManager.RequerySuggested -= value; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Runtime.InteropServices;
|
||||||
using System.Resources;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Samples
|
|||||||
/// The number of clicks on the popup button.
|
/// The number of clicks on the popup button.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty ClickCountProperty =
|
public static readonly DependencyProperty ClickCountProperty =
|
||||||
DependencyProperty.Register("ClickCount",
|
DependencyProperty.Register(nameof(ClickCount),
|
||||||
typeof (int),
|
typeof (int),
|
||||||
typeof (FancyPopup),
|
typeof (FancyPopup),
|
||||||
new FrameworkPropertyMetadata(0));
|
new FrameworkPropertyMetadata(0));
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Samples;
|
|
||||||
|
|
||||||
namespace WindowsFormsSample
|
namespace WindowsFormsSample
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
// to COM components. If you need to access a type in this assembly from
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
|||||||
Reference in New Issue
Block a user