Reputation: 379
I want to show a label for 3 seconds only and then disappear it. I am working on a WPF application.
public DispatcherTimer timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
I started timer from the function
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;
*/
}
Is this the right way or is there any other easy way ?
Upvotes: 1
Views: 2976
Reputation: 8634
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>
Upvotes: 5
Reputation: 38079
Set your Interval
to 3000 and then just hide the label in the Tick
event.
Upvotes: 4