tags:

views:

35

answers:

1

I have an Image and a Popup. When clicked on the Image popup should open.

I started like that and now I stuck.

        <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>

UPD... Ooops, actually I forgot... I'd like the popup to be shown not immediately but rather after a second or two. If it was just a click, It would be something else... (default action)

+1  A: 

Here is the solution of what you want to do. Delay time can be set at Storyboard definitions. Insert this code into new wpf app project Window.xaml file.

<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>
Eugene Cheverda
Oh thanks... it will work for any click. Now... If I want to show popup after a couple of seconds, but if user didn't wait and just pressed the button it will fire up a default event. for example shows a message?
Ike
Yes, it will fire up defined event and then also will fire the storyboard.
Eugene Cheverda