WPF弹出窗口跟随DataTemplate中的鼠标

时间:2015-04-19 12:26:07

标签: c# wpf xaml datatemplate

我正在制作弹出窗口跟随DataTemplate中的鼠标

我有以下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>

现在弹出窗口正在工作:我的意思是它在500ms后显示并隐藏(几乎正确)

我试图在移动MyImage控件时跟我的鼠标指针弹出一个弹出窗口。

怎么做?

0 个答案:

没有答案