TitleBar.xaml.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using Xamarin.Forms;
  5. using Xamarin.Forms.Xaml;
  6. namespace comal.timesheets
  7. {
  8. public class TitleBarItemsCollection : ObservableCollection<TitleBarItem> { }
  9. public class TitleBarIconsCollection : ObservableCollection<TitleBarIcon> { }
  10. [XamlCompilation(XamlCompilationOptions.Compile)]
  11. public partial class TitleBar
  12. {
  13. public static readonly BindableProperty HeaderProperty = BindableProperty.CreateAttached(nameof(Header), typeof(string), typeof(TitleBar), "");
  14. public String Header
  15. {
  16. get => (String)GetValue(HeaderProperty);
  17. set => SetValue(HeaderProperty, value);
  18. }
  19. public static readonly BindableProperty IconsProperty = BindableProperty.CreateAttached(nameof(Icons), typeof(TitleBarIconsCollection), typeof(TitleBar), null);
  20. public TitleBarIconsCollection Icons
  21. {
  22. get => (TitleBarIconsCollection)GetValue(IconsProperty);
  23. set => SetValue(IconsProperty,value);
  24. }
  25. public static readonly BindableProperty ItemsProperty = BindableProperty.CreateAttached(nameof(Items), typeof(TitleBarItemsCollection), typeof(TitleBar), null);
  26. public TitleBarItemsCollection Items
  27. {
  28. get => (TitleBarItemsCollection)GetValue(ItemsProperty);
  29. set => SetValue(ItemsProperty,value);
  30. }
  31. public static readonly BindableProperty HasBackButtonProperty = BindableProperty.CreateAttached(nameof(HasBackButton), typeof(bool), typeof(TitleBar), true);
  32. public bool HasBackButton
  33. {
  34. get => (bool)GetValue(HasBackButtonProperty);
  35. set => SetValue(HasBackButtonProperty, value);
  36. }
  37. public TitleBar()
  38. {
  39. Items = new TitleBarItemsCollection();
  40. Icons = new TitleBarIconsCollection();
  41. InitializeComponent();
  42. }
  43. private void TitleBarItem_Tapped(object sender, EventArgs e)
  44. {
  45. if (sender is Image image)
  46. if (image.BindingContext is TitleBarItem item)
  47. item.DoTap();
  48. }
  49. private void Back_Clicked(object sender, EventArgs e)
  50. {
  51. Navigation.PopAsync();
  52. }
  53. }
  54. }