MobileButton.xaml.cs 4.8 KB

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