触发时间延迟 [英] Time Delay on Trigger

查看:139
本文介绍了触发时间延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在表单上的WPF扩展器(后面的VB.NET代码支持的XAML)上为鼠标悬停事件添加时间延迟.这个鼠标悬停事件本质上触发了与单击相反的扩展-但我想在内容扩展之前稍等片刻.到目前为止,我还没有找到任何可以通过更广泛的互联网解决此问题的方法.

I wish to attach a time delay to a mouseover event on a WPF expander I have on my form (xaml supported by VB.NET code behind). This mouseover event essentially triggers the expansion as oppose to clicking - but I'd like a short wait before the content is expanded. So far I have not managed to find anything to solve this via the wider internet.

当前启用触发器的xaml代码为:

The current xaml code to enable the trigger is:

    <Style x:Key="HoverExpander" TargetType="{x:Type Expander}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="IsExpanded" Value="True" />
            </Trigger>
        </Style.Triggers>
    </Style>

此样式随后应用于:

<Expander Style="{StaticResource HoverExpander}" 
          HorizontalAlignment="Right"
          ExpandDirection="Left" 
          Height="Auto" 
          Width="Auto">
           <!-- Content here -->
</Expander>

请注意,我已经去除了其他美观性(例如边框,gridrefs等,以提高可读性).

Note that I've stripped out other aesthetics (such as borders, gridrefs etc for readability).

我认为应该有一些方法可以在MouseOver触发器上设置延迟,但是运气不好.可以在xaml中设置它,也可以在后面的代码中将其设置为事件.

I think there should be some way to set a delay on the MouseOver Trigger but haven't had much luck finding it. This could either be set in xaml or perhaps as an event in the code behind.

我目前正在研究此问题,因此当我找到解决方案时,请在此处发布.同时感谢任何想法.谢谢!

I'm working on this currently, so when I find a solution I shall post it here. Grateful for any ideas meantime. Thanks!

推荐答案

在MouseOver事件上使用EventTrigger,在Storyboard上使用BooleanAnimationUsingKeyFrames.在情节提要的时间轴中,您可以具有关键帧,以便动画等待一段时间才能影响您要更改的属性.

Use an EventTrigger on the MouseOver event and a Storyboard with a BooleanAnimationUsingKeyFrames instead. In the Timeline of the Storyboard, you could have KeyFrames, so that the animation waits for some time before it affects the properties you want to change.

这篇关于触发时间延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆