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:
Philipp Sumi
2013-11-16 21:37:36 +00:00
parent d2abe5238b
commit 008ea6ab2c

View File

@@ -23,12 +23,9 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.Remoting.Channels;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@@ -199,8 +196,23 @@ namespace Hardcodet.Wpf.TaskbarNotification
//events or override
popup.PopupAnimation = animation;
popup.Child = balloon;
//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;
//don't set the PlacementTarget as it causes the popup to become hidden if the
//TaskbarIcon's parent is hidden, too...
//popup.PlacementTarget = this;
@@ -291,6 +303,10 @@ namespace Hardcodet.Wpf.TaskbarNotification
//close the popup
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
if (element != null) SetParentTaskbarIcon(element, null);
}