1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using InABox.Wpf;
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- namespace InABox.WPF
- {
- /// <summary>
- /// Interaction logic for ProgressForm.xaml
- /// </summary>
- public partial class ProgressForm : ThemableWindow
- {
- private ImageSource? _image = null;
- private DoubleAnimation _fader = new DoubleAnimation(1d, 0.3d, new Duration(TimeSpan.FromMilliseconds(3000))) { AutoReverse = true };
- public string CancelText { get; init; }
- public bool HasCancelButton { get; init; }
- public delegate void CancelledEvent();
- public event CancelledEvent? OnCancelled;
- public Visibility CancelButtonVisibility => HasCancelButton ? Visibility.Visible : Visibility.Collapsed;
- private ProgressForm(string cancelText, bool hasCancelButton)
- {
- CancelText = cancelText;
- HasCancelButton = hasCancelButton;
- InitializeComponent();
- Topmost = true;
- Loaded += (sender, args) =>
- {
- _fader.Completed += (o, e) => Splash.BeginAnimation(Image.OpacityProperty, _fader);
- Splash.BeginAnimation(Image.OpacityProperty, _fader);
- };
- }
- public ProgressForm(): this("", false) { }
- public ProgressForm(string cancelText): this(cancelText, true) { }
-
- public ImageSource? DisplayImage
- {
- get => Splash.Source;
- set => Splash.Source = value;
- }
-
- public void UpdateWindow(string message)
- {
- if (Progress.Dispatcher.CheckAccess())
- Progress.Content = message;
- else
- Progress.Dispatcher.Invoke(() => { Progress.Content = message; });
- }
- public void CloseWindow()
- {
- if (Progress.Dispatcher.CheckAccess())
- Close();
- else
- Progress.Dispatcher.Invoke(() => { Close(); });
- }
- public string GetMessage()
- {
- return Progress.Content as string;
- }
- private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- if(e.ChangedButton == System.Windows.Input.MouseButton.Left)
- {
- DragMove();
- }
- }
- private void CancelButton_Click(object sender, RoutedEventArgs e)
- {
- OnCancelled?.Invoke();
- }
- }
- }
|