protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.tip_calculator); Toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); if (Toolbar != null) { SetSupportActionBar(Toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(false); } Calculate = FindViewById <Button>(Resource.Id.calculate); BillAmount = FindViewById <EditText>(Resource.Id.bill_amount); TipAmount = FindViewById <TextView>(Resource.Id.tip_amount); Calculate.Click += (s, e) => { var amount = Convert.ToDecimal(BillAmount.Text); TipAmount.Text = _tipCalculator.Calculate(amount).ToString("C2"); }; Calculate.Enabled = false; BillAmount.TextChanged += (s, e) => Calculate.Enabled = !string.IsNullOrEmpty(BillAmount.Text); }
public override void ViewDidLoad() { base.ViewDidLoad(); Title = "TipCalc"; Calculate.TouchUpInside += (s, e) => { var amount = Convert.ToDecimal(BillAmount.Text); TipAmount.Text = _tipCalculator.Calculate(amount).ToString("C2"); }; Calculate.Enabled = false; BillAmount.AddTarget((s, e) => Calculate.Enabled = !string.IsNullOrEmpty(BillAmount.Text), UIControlEvent.EditingChanged); }
private void Calculate() => TipAmount = _tipCalculator.Calculate(BillAmount);