Dispenser/DispenserUI/Views/Windows/EmergencyWindow.axaml.cs

58 lines
1.4 KiB
C#
Raw Normal View History

2024-08-16 07:20:09 +00:00
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using DispenserCommon.Scheduler;
namespace DispenserUI.Views.Windows;
public partial class EmergencyWindow : Window
{
private bool _isWhite = true;
public static readonly StyledProperty<string> BackGroupProperty =
AvaloniaProperty.Register<EmergencyWindow, string>(nameof(BackGround), "#ffffff");
public EmergencyWindow()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public string BackGround
{
get => GetValue(BackGroupProperty);
set => SetValue(BackGroupProperty, value);
}
protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);
JobScheduler.RemoveTask("ChangeBackGround");
}
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
// 定时切换背景颜色
JobScheduler.AddTask("ChangeBackGround", () =>
{
Dispatcher.UIThread.Invoke(() =>
{
BackGround = _isWhite ? "#FF0000" : "#ffffff";
_isWhite = !_isWhite;
});
}, 1000);
}
private void Confirm(object? sender, RoutedEventArgs e)
{
Close(true);
}
}