private void CreatePopup()
{
//check if the item itself is a popup
Popup popup = TrayPopup as Popup;
if (popup == null && TrayPopup != null)
{
//create an invisible popup that hosts the UIElement
popup = new Popup();
popup.AllowsTransparency = true;
//don't animate by default - devs can use attached
//events or override
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.
//If there is no DataContext, the TaskbarIcon assigns itself
if (popup != null)
{
UpdateDataContext(popup, null, DataContext);
}
//store a reference to the used tooltip
SetTrayPopupResolved(popup);
}