using System; using Xamarin.Forms; namespace InABox.Mobile { public interface IMobileToolItem { string Text { get; set; } ImageSource Image { get; set; } string Indicator { get; set; } bool IsEnabled { get; set; } bool IsVisible { get; set; } int ID { get; set; } event EventHandler Tapped; void DoTap(); int Row { get; set; } int Column { get; set; } } public partial class MobileMobileToolItem : BindableObject, IMobileToolItem { public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(MobileMobileToolItem), ""); public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(Image), typeof(ImageSource), typeof(MobileMobileToolItem), null); public ImageSource Image { get { return (ImageSource)GetValue(ImageProperty); } set { SetValue(ImageProperty, value); } } public static readonly BindableProperty IndicatorProperty = BindableProperty.Create(nameof(Indicator), typeof(string), typeof(MobileMobileToolItem), null); public string Indicator { get { return (string)GetValue(IndicatorProperty); } set { SetValue(IndicatorProperty, value); OnPropertyChanged(nameof(HasIndicator)); } } public bool HasIndicator => !String.IsNullOrWhiteSpace(Indicator); public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create( nameof(BackgroundColor), typeof(Color), typeof(MobileMobileToolItem), Color.White); public Color BackgroundColor { get => (Color)GetValue(BackgroundColorProperty); set => SetValue(BackgroundColorProperty, value); } public static readonly BindableProperty TextColorProperty = BindableProperty.Create( nameof(TextColor), typeof(Color), typeof(MobileMobileToolItem), Color.Black); public Color TextColor { get => (Color)GetValue(TextColorProperty); set => SetValue(TextColorProperty, value); } public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(MobileMobileToolItem), true); public bool IsEnabled { get { return (bool)GetValue(IsEnabledProperty); } set { SetValue(IsEnabledProperty, value); } } public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(MobileMobileToolItem), true); public bool IsVisible { get { return (bool)GetValue(IsVisibleProperty); } set { SetValue(IsVisibleProperty, value); } } public static readonly BindableProperty RowProperty = BindableProperty.Create(nameof(Row), typeof(Int32), typeof(MobileMobileToolItem)); public Int32 Row { get { return (Int32)GetValue(RowProperty); } set { SetValue(RowProperty, value); } } public static readonly BindableProperty ColumnProperty = BindableProperty.Create(nameof(Column), typeof(Int32), typeof(MobileMobileToolItem)); public Int32 Column { get { return (Int32)GetValue(ColumnProperty); } set { SetValue(ColumnProperty, value); } } public int ID { get; set; } public event EventHandler Tapped; private void UpdateIndicator() { // if (!String.IsNullOrWhiteSpace(Indicator)) // { // indicatorLbl.Text = Indicator; // indicatorFrame.IsVisible = true; // Task.Run(() => // { // Thread.Sleep(1000); // Device.BeginInvokeOnMainThread(() => // { // indicatorFrame.TranslateTo(0, -10, 250); // indicatorFrame.TranslateTo(0, 0, 250); // }); // }); // } // else // indicatorFrame.IsVisible = false; } public void DoTap() { //await toolFrame.TranslateTo(0, -15, 150); //await toolFrame.TranslateTo(0, 0, 150); Tapped?.Invoke(this, EventArgs.Empty); } } }