private void InitializeFuelEcoTypes() { var t1 = new FuelEconomyType() { Id = "lpk", Text = "L/100 km", DistanceText = "距离(千米)", FuelText = "用于燃料(升)" }; var t2 = new FuelEconomyType() { Id = "mpg", Text = "Miles per gallon", DistanceText = "距离(米)", FuelText = "用于燃料(加仑)" }; FuelEcoTypes.AddRange(new FuelEconomyType[] { t1, t2 }); }
public void OnCalculate() { double fual = double.Parse(Fuel); double distance = double.Parse(Distance); FuelEconomyType ecoType = SelectedFuelEcoType; double result = 0; switch (ecoType.Id) { case "lpk": result = fual / (distance / 100); break; case "mpg": result = distance / fual; break; default: break; } Result = result.ToString(); }