sharee.bike-App/ShareeSharedGuiLib/ViewModel/BarLevelInputViewModel.cs
Anja Müller-Meißner 0468955d49 Version 3.0.338
2022-09-08 09:55:14 +02:00

67 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;
namespace ShareeSharedGuiLib.ViewModel
{
/// <summary>
/// Bar based filling level view which shows filling level and allows to edit this level.
/// </summary>
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;
}
}
}