SukiDialog.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using Avalonia;
  4. using Avalonia.Controls.Primitives;
  5. using Avalonia.Media;
  6. using SukiUI.Dialogs;
  7. namespace SukiUI.Controls
  8. {
  9. public class SukiDialog : TemplatedControl, ISukiDialog
  10. {
  11. public static readonly StyledProperty<object?> ViewModelProperty = AvaloniaProperty.Register<SukiDialog, object?>(nameof(ViewModel));
  12. public object? ViewModel
  13. {
  14. get => GetValue(ViewModelProperty);
  15. set => SetValue(ViewModelProperty, value);
  16. }
  17. public static readonly StyledProperty<string?> TitleProperty = AvaloniaProperty.Register<SukiDialog, string?>(nameof(Title));
  18. public string? Title
  19. {
  20. get => GetValue(TitleProperty);
  21. set => SetValue(TitleProperty, value);
  22. }
  23. public static readonly StyledProperty<object?> ContentProperty = AvaloniaProperty.Register<SukiDialog, object?>(nameof(Content));
  24. public object? Content
  25. {
  26. get => GetValue(ContentProperty);
  27. set => SetValue(ContentProperty, value);
  28. }
  29. public static readonly StyledProperty<bool> IsViewModelOnlyProperty = AvaloniaProperty.Register<SukiDialog, bool>(nameof(IsViewModelOnly));
  30. internal bool IsViewModelOnly
  31. {
  32. get => GetValue(IsViewModelOnlyProperty);
  33. set => SetValue(IsViewModelOnlyProperty, value);
  34. }
  35. public static readonly StyledProperty<object?> IconProperty = AvaloniaProperty.Register<SukiDialog, object?>(nameof(Icon));
  36. public object? Icon
  37. {
  38. get => GetValue(IconProperty);
  39. set => SetValue(IconProperty, value);
  40. }
  41. public static readonly StyledProperty<bool> ShowCardBackgroundProperty = AvaloniaProperty.Register<SukiDialog, bool>(nameof(ShowCardBackground), defaultValue: true);
  42. public bool ShowCardBackground
  43. {
  44. get => GetValue(ShowCardBackgroundProperty);
  45. set => SetValue(ShowCardBackgroundProperty, value);
  46. }
  47. public static readonly StyledProperty<IBrush?> IconColorProperty = AvaloniaProperty.Register<SukiDialog, IBrush?>(nameof(IconColor));
  48. public IBrush? IconColor
  49. {
  50. get => GetValue(IconColorProperty);
  51. set => SetValue(IconColorProperty, value);
  52. }
  53. public static readonly StyledProperty<ObservableCollection<object>> ActionButtonsProperty = AvaloniaProperty.Register<SukiDialog, ObservableCollection<object>>(nameof(ActionButtons));
  54. public ObservableCollection<object> ActionButtons
  55. {
  56. get => GetValue(ActionButtonsProperty);
  57. set => SetValue(ActionButtonsProperty, value);
  58. }
  59. public ISukiDialogManager? Manager { get; set; }
  60. public Action<ISukiDialog>? OnDismissed { get; set; }
  61. public bool CanDismissWithBackgroundClick { get; set; }
  62. public SukiDialog()
  63. {
  64. ActionButtons = new ObservableCollection<object>();
  65. }
  66. public void Dismiss() => Manager?.TryDismissDialog(this);
  67. protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
  68. {
  69. base.OnApplyTemplate(e);
  70. IsViewModelOnly = ViewModel != null;
  71. }
  72. }
  73. }