可能重复:
Time Delay on Trigger
我在WPF中使用几个按钮来显示各种文件夹中的图像。所有按钮的Click
模式为Hover
。对于某些按钮,在悬停后,它会路由到函数OnButtonClick
。我想要做的是,只有在鼠标停留在X
秒的按钮之后,才能完成函数OnButtonClick
内的处理。
编辑: XAML代码:
<Button Name="Dresses" Content="Dresses" Click="OnButtonClickDresses" Grid.Row="2" Height="34" Width="85" VerticalAlignment="Center" Grid.Column="5" FontFamily="Tahoma" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center" Cursor="Hand" ClickMode="Hover">
<Button.Background>
<LinearGradientBrush>
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Green" Offset="1" />
</LinearGradientBrush>
</Button.Background>
</Button>
C#代码:
private void OnButtonClickDresses(object sender, RoutedEventArgs e)
{
//Code for delay
//Code which should run only if mouse on button after 5 seconds
}