问题
i want to show a label for a 3 seconds only and then disappear it. i am working in 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 right way ? or is there any other easy way ?
回答1:
Set your Interval
to 3000 and then just hide the label in the Tick
event.
回答2:
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>
来源:https://stackoverflow.com/questions/27648539/how-to-show-label-for-couple-of-seconds-in-wpf