mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-02-17 02:51:51 -05:00
CHG If a popup is being reused, but still has a parent, throw custom exception with more descriptive error message.
git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@179 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
@@ -23,12 +23,9 @@
|
|||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Runtime.Remoting.Channels;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
@@ -199,6 +196,21 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
//events or override
|
//events or override
|
||||||
popup.PopupAnimation = animation;
|
popup.PopupAnimation = animation;
|
||||||
|
|
||||||
|
//in case the balloon is cleaned up through routed events, the
|
||||||
|
//control didn't removed the balloon from its parent popup when
|
||||||
|
//if was closed the last time - just make sure it doesn't have
|
||||||
|
//a parent that is a popup
|
||||||
|
var parent = LogicalTreeHelper.GetParent(balloon) as Popup;
|
||||||
|
if (parent != null) parent.Child = null;
|
||||||
|
|
||||||
|
if (parent != null)
|
||||||
|
{
|
||||||
|
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.";
|
||||||
|
msg = String.Format(msg, balloon);
|
||||||
|
throw new InvalidOperationException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
popup.Child = balloon;
|
popup.Child = balloon;
|
||||||
|
|
||||||
//don't set the PlacementTarget as it causes the popup to become hidden if the
|
//don't set the PlacementTarget as it causes the popup to become hidden if the
|
||||||
@@ -291,6 +303,10 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
//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
|
||||||
|
//the balloon (then added to a new popup)
|
||||||
|
popup.Child = null;
|
||||||
|
|
||||||
//reset attached property
|
//reset attached property
|
||||||
if (element != null) SetParentTaskbarIcon(element, null);
|
if (element != null) SetParentTaskbarIcon(element, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user