本文介绍了帮我一个弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个图像和一个弹出窗口.单击图像"弹出窗口后,应该会打开.
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 ...糟糕,实际上我忘记了...我希望弹出窗口不立即显示,而是在一两秒钟后显示.如果只是单击,那将是其他...(默认操作)
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)
推荐答案
这是您要执行的操作的解决方案.可以在情节提要板定义中设置延迟时间.将此代码插入新的wpf应用程序项目Window.xaml文件.
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>
这篇关于帮我一个弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!