我想显示只有3秒的标签,然后消失了。 我在WPF应用程序的工作。
public DispatcherTimer timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
我开始计时从功能
timer.Start();
private void timer_Tick(object sender, EventArgs e)
{
/*
if timer equals 3 seconds then
timer.stop();
lblToast.Visibility = Visibility.Hidden;
else
lblToast.Visibility = Visibility.Visible;
*/
}
这是正确的方式? 或是否有任何其他简单的方法?
您所设定的Interval
到3000,然后就隐藏在标签Tick
事件。
Using Wpf animation you can do this very easily.For animation visit this link
<Label Content="Hello World">
<Label.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:3" Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Label.Triggers>
</Label>