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
c # wpf xaml datatemplate


source to share


No one has answered this question yet

Check out similar questions:

616
How to properly create a WPF application with one instance?
520
How do I use WPF bindings with RelativeSource?
506
In WPF, what are the differences between the x: Name and Name attributes?
385
What's the difference between StaticResource and DynamicResource in WPF?
361
WPF Image Resources
338
How do I programmatically exit a WPF application?
313
How do I get a TextBox to only accept numeric data in WPF?
168
Difference between Control Template and DataTemplate in WPF
47
WPF listbox empty dataset
0
WPF ListBox DataTemplate Mouse Inside



All Articles
Loading...
X
Show
Funny
Dev
Pics