Take the 2-minute tour ×

I've got a UserControl called myListItem that goes into ListBox'es. On mouse-over, it displays a pop-up window, and in that pop-up there's a scroll-view that the user might want to use to scroll the text in the view. I've made an event-handler that displays the pop-up when the mouse enters, but I'm struggeling a bit with when the mouse leaves. If the mouse leaves to the pop-up, the pop-up should stay up, but when the mouse leaves any other way, the pop-up should be disabled. Do you have any suggestions on how to solve this? I'd think there would be a way looking a bit like this:

void MouseLeave(object sender, MouseEventArgs e) {
    itemPopUp.IsOpen = false;



share|improve this question

1 Answer 1

Suppose you have this Popup XAML code:

<Popup x:Name="MyPopup">
    <Border Width="200" Height="200" BorderThickness="1" BorderBrush="Black" Background="Pink"
            MouseLeave="Border_MouseLeave" MouseMove="Border_MouseMove" >

<TextBlock x:Name="MouseLeaveLoc" Text="N/A" />

and this in code behind (C#):

private void Border_MouseLeave(object sender, MouseEventArgs e)
    MouseLeaveLoc.Text = mouseLoc.ToString();

private Point mouseLoc;
private void Border_MouseMove(object sender, MouseEventArgs e)
    mouseLoc = e.GetPosition(MyPopup);
    mouseLoc.X -= MyPopup.HorizontalOffset;
    mouseLoc.Y -= MyPopup.VerticalOffset;

mouseLoc contains the X,Y value relative to your popup content (here a Border control).

share|improve this answer
Hi, and thanks for your answer. :-) I hadn't thought about doing the subtraction you do in MouseMove(). If I understand you correctly, you suggest that I do the calculation myself, rather than using builtin functions? –  niklassaers-vc Feb 24 '09 at 14:51
Is there no hit-test associated with a Point? Something like this perhaps? MyPopup.HitTest(e.GetPosition(null)) –  niklassaers-vc Feb 25 '09 at 13:08

Your Answer


