代码之家  ›  专栏  ›  技术社区  ›  iLemming

请帮我弹出一个窗口

  •  0
  • iLemming  · 技术社区  · 14 年前

    我有一个图像和一个弹出窗口。当点击时,弹出的图像应该会打开。

    我就是这样开始的,现在我坚持下来了。

            <Image x:Name="LockImage" Source="/Lock.png">
                <Image.Triggers>
                    <EventTrigger RoutedEvent="MouseDown">
                        // ?????? WHAT's here?
                    </EventTrigger>
                </Image.Triggers>
            </Image>
            <Popup x:Name="LockPopup" PlacementTarget="{Binding ElementName=LockImage}">
                <TextBlock Text="This is a popup" />
            </Popup>
    

    升级。。。哦,实际上我忘了。。。我希望弹出显示不是立即,而是在一两秒钟后。如果它只是一个点击,它将是其他东西(默认操作)

    1 回复  |  直到 14 年前
        1
  •  2
  •   Eugene Cheverda    14 年前

    这是你想做的事情的解决方案。延迟时间可以在序列图像板定义中设置。将此代码插入新的wpf app project Window.xaml文件。

    <Window.Resources>
            <Storyboard x:Key="ShowPopup">
                <BooleanAnimationUsingKeyFrames Storyboard.TargetName="LockPopup" Storyboard.TargetProperty="(Popup.IsOpen)">
                    <DiscreteBooleanKeyFrame KeyTime="00:00:00.5" Value="True" />
                </BooleanAnimationUsingKeyFrames>
            </Storyboard>
    
            <Storyboard x:Key="HidePopup" Storyboard.TargetName="LockPopup" Storyboard.TargetProperty="(Popup.IsOpen)">
                <BooleanAnimationUsingKeyFrames>
                    <DiscreteBooleanKeyFrame KeyTime="00:00:00.5" Value="False" />
                </BooleanAnimationUsingKeyFrames>
            </Storyboard>
        </Window.Resources>
        <Grid x:Name="grid" ShowGridLines="True">
            <Image x:Name="LockImage" Stretch="None" >
                <Image.Source>
                    <DrawingImage>
                        <DrawingImage.Drawing>
                            <GeometryDrawing Brush="Black">
                                <GeometryDrawing.Geometry>
                                    <EllipseGeometry RadiusX="10" RadiusY="10"/>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                        </DrawingImage.Drawing>
                    </DrawingImage>
                </Image.Source>
                <Image.Triggers>
                    <EventTrigger RoutedEvent="Image.MouseLeftButtonDown">
                        <BeginStoryboard Storyboard="{StaticResource ShowPopup}"/>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="Image.MouseLeave">
                        <BeginStoryboard Storyboard="{StaticResource HidePopup}"/>
                    </EventTrigger>
                </Image.Triggers>
            </Image>
            <Popup x:Name="LockPopup" PlacementTarget="{Binding ElementName=LockImage}" DataContext="{Binding}" Placement="Bottom">
                <TextBlock Text="This is a popup" Background="White" Foreground="Black" />
            </Popup>       
        </Grid>