[英]label disappears if the countdown timer gets zero
我有一个显示倒数计时器的文本块(tbTime)。 当它变为零时,Textblock (tbTime) 仍显示零值。 但我想让这个文本块(tbTime)在倒数计时器归零后消失。 有人可以帮我吗?
C#代码
public partial class InfoScreen : Window
{
DispatcherTimer timer;
TimeSpan time;
public InfoScreen()
{
InitializeComponent();
AppearingNext();
time = TimeSpan.FromSeconds(10);
timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
tbTime.Text = time.ToString("ss");
if (time == TimeSpan.Zero) timer.Stop();
time = time.Add(TimeSpan.FromSeconds(-1));
}, Application.Current.Dispatcher);
if (tbTime.Text == "00") //My code doesn't work!
{
tbTime.Visibility = Visibility.Hidden;
}
}
private async void AppearingNext()
{
await Task.Delay(TimeSpan.FromSeconds(10));
VisbilityPanel.Visibility = Visibility.Visible;
}
private void AgreementClick(object sender, RoutedEventArgs e)
{
var registration = new Reset_Register();
registration.Show();
Close();
}
}
一种解决方案是将隐藏文本块的代码放入计时器的回调中:
timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate {
tbTime.Text = time.ToString("ss");
if (tbTime.Text == "00") {
tbTime.Visibility = Visibility.Hidden;
}
if (time == TimeSpan.Zero) timer.Stop();
time = time.Add(TimeSpan.FromSeconds(-1));
}, Application.Current.Dispatcher);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.