private void InitializePopup(FrameworkElement newPopup) { if (ReferenceEquals(newPopup, _tPopup)) { return; } if (_tPopup != null) { _tPopup.Opened -= OnPopupOpened; _tPopup.Closed -= OnPopupClosed; } _tPopup = newPopup.AsPopup(); if (_tPopup != null) { _tPopup.Opened += OnPopupOpened; _tPopup.Closed += OnPopupClosed; } }