using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace comal.timesheets { public class TitleBarItemsCollection : ObservableCollection { } public class TitleBarIconsCollection : ObservableCollection { } [XamlCompilation(XamlCompilationOptions.Compile)] public partial class TitleBar { public static readonly BindableProperty HeaderProperty = BindableProperty.CreateAttached(nameof(Header), typeof(string), typeof(TitleBar), ""); public String Header { get => (String)GetValue(HeaderProperty); set => SetValue(HeaderProperty, value); } public static readonly BindableProperty IconsProperty = BindableProperty.CreateAttached(nameof(Icons), typeof(TitleBarIconsCollection), typeof(TitleBar), null); public TitleBarIconsCollection Icons { get => (TitleBarIconsCollection)GetValue(IconsProperty); set => SetValue(IconsProperty,value); } public static readonly BindableProperty ItemsProperty = BindableProperty.CreateAttached(nameof(Items), typeof(TitleBarItemsCollection), typeof(TitleBar), null); public TitleBarItemsCollection Items { get => (TitleBarItemsCollection)GetValue(ItemsProperty); set => SetValue(ItemsProperty,value); } public static readonly BindableProperty HasBackButtonProperty = BindableProperty.CreateAttached(nameof(HasBackButton), typeof(bool), typeof(TitleBar), true); public bool HasBackButton { get => (bool)GetValue(HasBackButtonProperty); set => SetValue(HasBackButtonProperty, value); } public TitleBar() { Items = new TitleBarItemsCollection(); Icons = new TitleBarIconsCollection(); InitializeComponent(); } private void TitleBarItem_Tapped(object sender, EventArgs e) { if (sender is Image image) if (image.BindingContext is TitleBarItem item) item.DoTap(); } private void Back_Clicked(object sender, EventArgs e) { Navigation.PopAsync(); } } }