I have a pop up control inside a UserControl:
<UserControl ....>
<Popup x:Name="popUp" IsOpen="False" AllowsTransparency="True" LostFocus="popUp_LostFocus">
....
</Popup>
</UserControl>
The popup has a LostFocus Event:
private void popUp_LostFocus(object sender, RoutedEventArgs e)
{
...
}
But when I use the user control in a Window and the pop up lost the focus, the event not working.
Quoting MSDN on Popup.LogicalChildren:
... The child content is not added to the visual tree that contains the Popup control. Instead, the child content is rendered in a separate window that has its own visual tree when the IsOpen property is set to true.
Since the pop up is spawned in it's own window, it can't lose focus (to controls in another window). Instead register to the Closed event, occurs when the IsOpen property changes to false.