ActionButton.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Input;
  7. using Syncfusion.DocIO.DLS;
  8. using Xamarin.Forms;
  9. using Xamarin.Forms.Xaml;
  10. using XF.Material.Forms.Resources.Typography;
  11. namespace comal.timesheets
  12. {
  13. public class ActionButtonClickEventArgs : EventArgs
  14. {
  15. public object Tag { get; private set; }
  16. public ActionButtonClickEventArgs(object tag)
  17. {
  18. Tag = tag;
  19. }
  20. }
  21. public delegate void ActionButtonClickEvent(object sender, ActionButtonClickEventArgs args);
  22. [XamlCompilation(XamlCompilationOptions.Compile)]
  23. public partial class ActionButton
  24. {
  25. public event ActionButtonClickEvent Clicked;
  26. public static readonly BindableProperty TagProperty = BindableProperty.Create(
  27. nameof(Tag),
  28. typeof(object),
  29. typeof(ActionButton));
  30. public object Tag
  31. {
  32. get => GetValue(TagProperty);
  33. set => SetValue(TagProperty, value);
  34. }
  35. public static readonly BindableProperty OrientationProperty = BindableProperty.Create(
  36. nameof(Orientation),
  37. typeof(StackOrientation),
  38. typeof(ActionButton),
  39. StackOrientation.Horizontal);
  40. public StackOrientation Orientation
  41. {
  42. get => (StackOrientation)GetValue(OrientationProperty);
  43. set => SetValue(OrientationProperty, value);
  44. }
  45. public static readonly BindableProperty ImageProperty = BindableProperty.Create(
  46. nameof(Image),
  47. typeof(ImageSource),
  48. typeof(ActionButton)
  49. );
  50. public ImageSource Image
  51. {
  52. get => GetValue(ImageProperty) as ImageSource;
  53. set => SetValue(ImageProperty, value);
  54. }
  55. public static readonly BindableProperty TextProperty = BindableProperty.Create(
  56. nameof(Text),
  57. typeof(String),
  58. typeof(ActionButton)
  59. );
  60. public String Text
  61. {
  62. get => (String)GetValue(TextProperty);
  63. set => SetValue(TextProperty, value);
  64. }
  65. public static readonly BindableProperty AlertProperty = BindableProperty.Create(
  66. nameof(Alert),
  67. typeof(String),
  68. typeof(ActionButton)
  69. );
  70. public String Alert
  71. {
  72. get => (String)GetValue(AlertProperty);
  73. set => SetValue(AlertProperty, value);
  74. }
  75. public static readonly BindableProperty TextColorProperty = BindableProperty.Create(
  76. nameof(TextColor),
  77. typeof(Color),
  78. typeof(ActionButton),
  79. XF.Material.Forms.Material.Color.OnSecondary);
  80. public Color TextColor
  81. {
  82. get => (Color)GetValue(TextColorProperty);
  83. set => SetValue(TextColorProperty, value);
  84. }
  85. public static readonly BindableProperty TypeScaleProperty = BindableProperty.Create(
  86. nameof(TypeScale),
  87. typeof(MaterialTypeScale),
  88. typeof(ActionButton),
  89. MaterialTypeScale.Button);
  90. public MaterialTypeScale TypeScale
  91. {
  92. get => (MaterialTypeScale)GetValue(TypeScaleProperty);
  93. set => SetValue(TypeScaleProperty, value);
  94. }
  95. public new static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(
  96. nameof(BackgroundColor),
  97. typeof(Color),
  98. typeof(ActionButton),
  99. XF.Material.Forms.Material.Color.Secondary);
  100. public new Color BackgroundColor
  101. {
  102. get => (Color)GetValue(BackgroundColorProperty);
  103. set => SetValue(BackgroundColorProperty, value);
  104. }
  105. public static readonly BindableProperty BorderColorProperty = BindableProperty.Create(
  106. nameof(BorderColor),
  107. typeof(Color),
  108. typeof(ActionButton),
  109. XF.Material.Forms.Material.Color.SecondaryVariant);
  110. public Color BorderColor
  111. {
  112. get => (Color)GetValue(BorderColorProperty);
  113. set => SetValue(BorderColorProperty, value);
  114. }
  115. public static readonly BindableProperty PaddingProperty = BindableProperty.Create(
  116. nameof(Padding),
  117. typeof(Thickness),
  118. typeof(ActionButton),
  119. new Thickness(5));
  120. public new Thickness Padding
  121. {
  122. get => (Thickness)GetValue(PaddingProperty);
  123. set => SetValue(PaddingProperty, value);
  124. }
  125. public ActionButton()
  126. {
  127. InitializeComponent();
  128. Alert = "";
  129. }
  130. private void _frame_OnClicked(object sender, EventArgs e)
  131. {
  132. Clicked?.Invoke(this, new ActionButtonClickEventArgs(Tag));
  133. }
  134. }
  135. }