private static bool CheckClose(Popup popup, DependencyObject element)
 {
     if (popup != null && popup.Child != null)
     {
         object o = popup.Child.FindCommonVisualAncestor(element);
         return popup.FindCommonVisualAncestor(element) != null;
     }
     return false;
 }