Files
petwash/PetWashControl/Views/CompletionDialog.xaml.cs
2026-02-27 17:46:50 +08:00

58 lines
1.4 KiB
C#

using System;
using System.Windows;
using System.Windows.Threading;
namespace PetWashControl.Views
{
public partial class CompletionDialog : Window
{
private DispatcherTimer? _countdownTimer;
private int _remainingSeconds = 30;
public CompletionDialog()
{
InitializeComponent();
StartCountdown();
}
private void StartCountdown()
{
_countdownTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
_countdownTimer.Tick += CountdownTimer_Tick;
_countdownTimer.Start();
}
private void CountdownTimer_Tick(object? sender, EventArgs e)
{
_remainingSeconds--;
if (_remainingSeconds > 0)
{
CountdownText.Text = $"{_remainingSeconds}秒后自动返回首页";
}
else
{
_countdownTimer?.Stop();
DialogResult = true;
Close();
}
}
private void OkButton_Click(object sender, RoutedEventArgs e)
{
_countdownTimer?.Stop();
DialogResult = true;
Close();
}
protected override void OnClosed(EventArgs e)
{
_countdownTimer?.Stop();
base.OnClosed(e);
}
}
}