private void ChangeButtons(bool FormOpen) { if (FormOpen) { ApplicationBar.Buttons.RemoveAt(0); ApplicationBarIconButton b = new ApplicationBarIconButton(); b.Text = "add address"; b.IconUri = new Uri("/Toolkit.Content/ApplicationBar.Add.png", UriKind.Relative); b.Click += AddAddress_Click; ApplicationBar.Buttons.Add(b); } else { ApplicationBar.Buttons.RemoveAt(0); ApplicationBarIconButton b = new ApplicationBarIconButton(); b.Text = "submit"; b.IconUri = new Uri("/Toolkit.Content/ApplicationBar.Check.png", UriKind.Relative); b.Click += async(e2, s2) => { try { var Province = ""; if (State.Items.Count == 0) { Province = null; } else { Province = State.SelectedItem.ToString(); } var Result = await api.AddAddress(Customer.Email, Firstname.Text, Lastname.Text, Country.SelectedItem.ToString(), City.Text, Street.Text, PostalCode.Text, Phone.Text, Province); if (Result) { CustomMessageBox messageBox = new CustomMessageBox { Message = "Address added successfully", Title = "Add Success", LeftButtonContent = "OK" }; messageBox.Show(); messageBox.Dismissed += (s3, e3) => { if (e3.Result == CustomMessageBoxResult.LeftButton) { AddressForm.Visibility = System.Windows.Visibility.Collapsed; } }; } } catch (Exception ex) { } }; ApplicationBar.Buttons.Add(b); } }