private class Model : BaseViewModel
{
private const double InitialMs = 1000;
public Model()
{
Title = Resource.ConverterSquareTitle;
ActiveButton = nameof(MsValue);
MsValue = InitialMs;
}
#region Propertyes
/*
Квадратный метр (км2) SquareMsLabel MsValue
Квадратный километр (км2) SquareKmsLabel KmValue
Ар «соток» (а) SquareArLabel ArValue
Гектар (га) SquareGaLabel GaValue
Акр SquareAcrLabel AcrValue
Квадратная миля SquareMileLabel MileValue
Квадратный ярд (yd2) SquareYardLabel YardValue
Квадратный фут (ft2) SquareFtLabel FtValue
*/
double Ms2Km() => MsValue / 1000000;
double Ms2Acr() => MsValue / 4046.86;
double Ms2Ga() => MsValue / 10000;
double Ms2Ar() => MsValue / 100;
double Km2Mile() => KmValue / 2.58999;
double Ms2Yards() => MsValue * 1.19599;
double Ms2Ft() => MsValue * 10.7639;
#region MsValue
private double _ms = InitialMs;
public double MsValue
{
get => _ms;
set
{
SetProperty(ref _ms, value);
if (ActiveButton != nameof(MsValue)) return;
KmValue = Ms2Km();
ArValue = Ms2Ar();
GaValue = Ms2Ga();
AcrValue = Ms2Acr();
MileValue = Km2Mile();
YardValue = Ms2Yards();
FtValue = Ms2Ft();
}
}
#endregion
/// Ниже куча абсолютно аналогичного кода
private class Model : BaseViewModel
{
private const double KlConst = 273.15;
private const double InitialKelvin = KlConst + 20;
public Model()
{
Title = Resource.ConverterTemperatureTitle;
ActiveButton = nameof(KValue);
KValue = InitialKelvin;
}
#region Props
private double K2C() => KValue - KlConst;
private double C2K() => CValue + KlConst;
private double K2F() => (KValue - KlConst) * (9D / 5) + 32;
private double F2K() => (FValue - 32) * 5d / 9 + KlConst;
private double K2Re() => (4d / 5) * (KValue - KlConst);
private double Re2K() => (5d / 4) * ReValue + KlConst;
private void Calculate()
{
if (ActiveButton != nameof(CValue)) CValue = K2C();
if (ActiveButton != nameof(FValue)) FValue = K2F();
if (ActiveButton != nameof(ReValue)) ReValue = K2Re();
}
#region CValue
private double _cValue;
public double CValue
{
get => _cValue;
set
{
SetProperty(ref _cValue, value);
if (ActiveButton != nameof(CValue)) return;
KValue = C2K();
Calculate();
}
}
#endregion
#region FValue
private double _fValue;
public double FValue
{
get => _fValue;
set
{
SetProperty(ref _fValue, value);
if (ActiveButton != nameof(FValue)) return;
KValue = F2K();
Calculate();
}
}
#endregion
#region ReValue
private double _reValue;
public double ReValue
{
get => _reValue;
set
{
SetProperty(ref _reValue, value);
if (ActiveButton != nameof(ReValue)) return;
KValue = Re2K();
Calculate();
}
}
#endregion
#region KValue
private double _kValue;
public double KValue
{
get => _kValue;
set
{
SetProperty(ref _kValue, value);
if (ActiveButton != nameof(KValue)) return;
Calculate();
}
}
#endregion
#endregion
#region ActiveButton
private string _activeButton = "";
public string ActiveButton
{
get => _activeButton;
set => SetProperty(ref _activeButton, value);
}
#endregion
}