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
}
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:SpecialForcesDirectory.Views;assembly=SpecialForcesDirectory"
xmlns:code="clr-namespace:SpecialForcesDirectory.Code;assembly=SpecialForcesDirectory"
x:Class="SpecialForcesDirectory.Page1" >
<FlyoutItem Title="Main" FlyoutDisplayOptions="AsMultipleItems" Route="main">
<Tab Title="{Binding AppShellMain,Mode=OneWay }" Icon="outline_home_white_48.png">
<ShellContent Title="{Binding AppShellMain, Mode=OneWay }" Icon="outline_home_white_48.png" Route="quota" ContentTemplate="{DataTemplate views:QuotaPage}"/>
</Tab>
<Tab Title="{Binding AppShellNotes , Mode=OneWay}" Icon="outline_bookmarks_white_48.png">
<ShellContent Title="{Binding AppShellNotes , Mode=OneWay}" Icon="outline_bookmarks_white_48.png" Route="notes" ContentTemplate="{DataTemplate views:NotesPage}"/>
</Tab>
</FlyoutItem>
<ShellContent Title="{Binding AppShellInfo, Mode=OneWay}" StyleId="NONE" Route="about" Icon="outline_error_outline_white_24.png" ContentTemplate="{DataTemplate views:AboutPage}"/>
<ShellContent Title="{Binding AppShellSettings, Mode=OneWay}" Icon="outline_settings_white_48.png" StyleId="NONE" Route="settings" ContentTemplate="{DataTemplate settings:SettingPage}"/>
</Shell>