MobileSearchBar.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. using XF.Material.Forms.Resources.Typography;
  9. namespace InABox.Mobile
  10. {
  11. public class MobileSearchBarTextChangedArgs : EventArgs
  12. {
  13. public string Text { get; private set; }
  14. public MobileSearchBarTextChangedArgs(String text)
  15. {
  16. Text = text;
  17. }
  18. }
  19. public delegate void MobileSearchBatTextChanged(object sender, MobileSearchBarTextChangedArgs args);
  20. [XamlCompilation(XamlCompilationOptions.Compile)]
  21. public partial class MobileSearchBar
  22. {
  23. private static readonly BindableProperty BorderColorProperty = BindableProperty.Create(
  24. nameof(BorderColor),
  25. typeof(Color),
  26. typeof(MobileSearchBar),
  27. Color.Gray);
  28. public Color BorderColor
  29. {
  30. get => (Color)GetValue(BorderColorProperty);
  31. set => SetValue(BorderColorProperty, value);
  32. }
  33. private static readonly BindableProperty TextBackgroundColorProperty = BindableProperty.Create(
  34. nameof(TextBackgroundColor),
  35. typeof(Color),
  36. typeof(MobileSearchBar),
  37. XF.Material.Forms.Material.Color.Surface);
  38. public Color TextBackgroundColor
  39. {
  40. get => (Color)GetValue(TextBackgroundColorProperty);
  41. set => SetValue(TextBackgroundColorProperty, value);
  42. }
  43. private static readonly BindableProperty TextColorProperty = BindableProperty.Create(
  44. nameof(TextColor),
  45. typeof(Color),
  46. typeof(MobileSearchBar),
  47. XF.Material.Forms.Material.Color.OnSurface);
  48. public Color TextColor
  49. {
  50. get => (Color)GetValue(TextColorProperty);
  51. set => SetValue(TextColorProperty, value);
  52. }
  53. private static readonly BindableProperty TextSizeProperty = BindableProperty.Create(
  54. nameof(TextSize),
  55. typeof(double),
  56. typeof(MobileSearchBar),
  57. 16D);
  58. public double TextSize
  59. {
  60. get => (double)GetValue(TextSizeProperty);
  61. set => SetValue(TextSizeProperty, value);
  62. }
  63. private static readonly BindableProperty PlaceHolderProperty = BindableProperty.Create(
  64. nameof(PlaceHolder),
  65. typeof(String),
  66. typeof(MobileSearchBar)
  67. );
  68. public String PlaceHolder
  69. {
  70. get => (String)GetValue(PlaceHolderProperty);
  71. set => SetValue(PlaceHolderProperty, value);
  72. }
  73. public event MobileSearchBatTextChanged TextChanged;
  74. public MobileSearchBar()
  75. {
  76. InitializeComponent();
  77. }
  78. private void _search_OnTextChanged(object sender, TextChangedEventArgs e)
  79. {
  80. TextChanged?.Invoke(this,new MobileSearchBarTextChangedArgs(e.NewTextValue));
  81. }
  82. }
  83. }