MobileCard.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Windows.Input;
  4. using Xamarin.Forms;
  5. namespace InABox.Mobile
  6. {
  7. public class MobileCard : Frame
  8. {
  9. private readonly BindableProperty IsClickableProperty = BindableProperty.Create(
  10. nameof(IsClickable),
  11. typeof(bool),
  12. typeof(MobileCard),
  13. false);
  14. public bool IsClickable
  15. {
  16. get => (bool)GetValue(IsClickableProperty);
  17. set => SetValue(IsClickableProperty, value);
  18. }
  19. public MobileCard()
  20. {
  21. CornerRadius = 5;
  22. Margin = 0;
  23. Padding = 2;
  24. BorderColor = Color.Gray;
  25. BackgroundColor = Color.White;
  26. HasShadow = false;
  27. IsEnabled = true;
  28. GestureRecognizers.Add(new TapGestureRecognizer
  29. {
  30. Command = new Command(OnClick)
  31. });
  32. }
  33. public event EventHandler Clicked;
  34. protected virtual async void OnClick()
  35. {
  36. if (IsEnabled && IsClickable)
  37. {
  38. Scale = 0.5;
  39. await this.ScaleTo(1, 150);
  40. Clicked?.Invoke(this, EventArgs.Empty);
  41. }
  42. }
  43. }
  44. }