private void Calculate_Click(object sender, RoutedEventArgs e) { double fuel = double.Parse(viewModel.Fuel); double distance = double.Parse(viewModel.Distance); FuelEconomyType ecoType = viewModel.SelectedFuelEconomyType; double result = 0; switch (ecoType.Id) { case "lpk": result = fuel / (distance / 100); break; case "mpg": result = distance / fuel; break; default: break; } viewModel.Result = result.ToString(); }
private void InitializeFuelEcoTypes() { var t1 = new FuelEconomyType() { Id = "lpk", Text = "L/100 km", DistanceText = "Distance (kilometers)", FuelText = "Fuel used (liters)" }; var t2 = new FuelEconomyType() { Id = "mpg", Text = "Miles per gallon", DistanceText = "Distance (miles)", FuelText = "Fuel used (gallons)" }; fuelEcoTypes = new List <FuelEconomyType>() { t1, t2 }; }