sharee.bike-App/ShareeSharedGuiLib/ViewModel/BarLevelInputViewModel.cs

68 lines
1.4 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;
namespace ShareeSharedGuiLib.ViewModel
{
2022-09-06 16:08:19 +02:00
/// <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;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public int? _Maximum = null;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public int? Maximum
{
get => _Maximum;
set
{
if (_Maximum == value)
{
// Nothing to do because nothing changed.
return;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
_Maximum = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MaximumText)));
}
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public string MaximumText => Maximum != null
? Maximum.Value.ToString()
: string.Empty;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public int? _Current = null;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public int? Current
{
get => _Current;
set
{
if (_Current == value)
{
// Nothing to do because nothing changed.
return;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
_Current = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Current)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentText)));
}
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public string CurrentText
{
get => Current != null
? Current.Value.ToString()
: string.Empty;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
set => Current = int.TryParse(value, out int newCurrent) ? (int?)newCurrent : null;
}
}
2022-08-30 15:42:25 +02:00
}