WPF Popup follows mouse in DataTemplate

I am struggling with creating a popup with mouse in DataTemplate

I have the following DataTemplate:

<DataTemplate>
    <StackPanel x:Name="MyPanel">
        <Popup x:Name="MyPopup"  Visibility="Visible" AllowsTransparency="True" Placement="MousePoint">
            something here
        </Popup>
        <controls1:ImageLoader x:Name="MyImage" Margin="10,10,0,0" Source="{Binding ImageUri}" Width="100" Height="100">
        </controls1:ImageLoader>
    </StackPanel>

    <DataTemplate.Triggers>
        <EventTrigger RoutedEvent="MyImage.MouseEnter" >
            <BeginStoryboard>
                <Storyboard>
                    <BooleanAnimationUsingKeyFrames
                        Storyboard.TargetName="MyPopup"
                        Storyboard.TargetProperty="IsOpen"
                        Duration="0:0:0.5">
                            <DiscreteBooleanKeyFrame Value="True" KeyTime="100%"/>
                    </BooleanAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>

        <EventTrigger RoutedEvent="MyPanel.MouseLeave" >
            <BeginStoryboard>
                <Storyboard>
                    <BooleanAnimationUsingKeyFrames
                        Storyboard.TargetName="MyPopup"
                        Storyboard.TargetProperty="IsOpen"
                        Duration="0:0:0.01">
                            <DiscreteBooleanKeyFrame Value="False" KeyTime="100%"/>
                    </BooleanAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </DataTemplate.Triggers>
</DataTemplate>

      

Now the popup is working: I mean it shows after 500ms and hides (almost correctly)

I am trying to make a popup follow the mouse while moving around a control MyImage

.

How to do it?

+3


source to share





All Articles