using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Windows.Input; using Xamarin.Forms; namespace ShareeSharedGuiLib.ViewModel { /// /// Bar based filling level view which shows filling level and allows to edit this level. /// public class BarLevelInputViewModel : INotifyPropertyChanged { public new event PropertyChangedEventHandler PropertyChanged; public int? _Maximum = null; public int? Maximum { get => _Maximum; set { if (_Maximum == value) { // Nothing to do because nothing changed. return; } _Maximum = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MaximumText))); } } public string MaximumText => Maximum != null ? Maximum.Value.ToString() : string.Empty; public int? _Current = null; public int? Current { get => _Current; set { if (_Current == value) { // Nothing to do because nothing changed. return; } _Current = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Current))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentText))); } } public string CurrentText { get => Current != null ? Current.Value.ToString() : string.Empty; set => Current = int.TryParse(value, out int newCurrent) ? (int?)newCurrent : null; } } }