MultiButtonScroller.xaml.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Xamarin.Forms;
  7. using Xamarin.Forms.Xaml;
  8. namespace PRS.Mobile.CustomControls
  9. {
  10. [XamlCompilation(XamlCompilationOptions.Compile)]
  11. public partial class MultiButtonScroller : ContentView
  12. {
  13. public MultiButtonScroller()
  14. {
  15. InitializeComponent();
  16. }
  17. public void LoadButtons(List<Button> buttons)
  18. {
  19. foreach (Button button in buttons)
  20. {
  21. button.BackgroundColor = Color.FromHex("#15C7C1");
  22. button.Margin = 5;
  23. button.CornerRadius = 10;
  24. button.TextColor = Color.White;
  25. button.FontAttributes = FontAttributes.Bold;
  26. button.VerticalOptions = LayoutOptions.CenterAndExpand;
  27. button.HeightRequest = 60;
  28. button.Padding = new Thickness(10, 5, 10, 5);
  29. button.FontSize = Device.GetNamedSize(NamedSize.Medium, button);
  30. buttonsStackLayout.Children.Add(button);
  31. }
  32. Label labelLeft = new Label()
  33. {
  34. Text = "<",
  35. VerticalOptions = LayoutOptions.Center,
  36. VerticalTextAlignment = TextAlignment.Center,
  37. FontAttributes = FontAttributes.Bold,
  38. Margin = new Thickness(5, 0, 0, 0)
  39. };
  40. labelLeft.FontSize = Device.GetNamedSize(NamedSize.Large, labelLeft);
  41. Label labelRight = new Label()
  42. {
  43. Text = ">",
  44. VerticalOptions = LayoutOptions.Center,
  45. VerticalTextAlignment = TextAlignment.Center,
  46. FontAttributes = FontAttributes.Bold,
  47. Margin = new Thickness(0, 0, 5, 0)
  48. };
  49. labelRight.FontSize = Device.GetNamedSize(NamedSize.Large, labelRight);
  50. labelLeft.SetValue(Grid.ColumnProperty, 0);
  51. labelLeft.SetValue(Grid.RowProperty, 0);
  52. labelRight.SetValue(Grid.ColumnProperty, 2);
  53. labelRight.SetValue(Grid.RowProperty, 0);
  54. grid.Children.Add(labelLeft);
  55. grid.Children.Add(labelRight);
  56. }
  57. public void AddButton(Button button)
  58. {
  59. button.BackgroundColor = Color.FromHex("#15C7C1");
  60. button.Margin = 5;
  61. button.CornerRadius = 10;
  62. button.TextColor = Color.White;
  63. button.FontAttributes = FontAttributes.Bold;
  64. button.VerticalOptions = LayoutOptions.CenterAndExpand;
  65. button.HeightRequest = 60;
  66. button.Padding = 5;
  67. button.FontSize = Device.GetNamedSize(NamedSize.Medium, button);
  68. buttonsStackLayout.Children.Add(button);
  69. }
  70. }
  71. }