private async void ClearDataButton_Click(object sender, RoutedEventArgs e) { ContactNameBox.Focus(); var settings = new MetroDialogSettings() { AffirmativeButtonText = "No", NegativeButtonText = "Yes", }; var result = await this.ShowMessageAsync("Are you sure?", "You will be clearing everything", MessageDialogStyle.AffirmativeAndNegative, settings); if (result == MessageDialogResult.Negative) { foreach (UIElement el in GenericInfoGrid.Children) { if (el.GetType() == typeof(TextBox)) { ((TextBox)(el)).Clear(); } } foreach (UIElement el in DeviceInfoGrid.Children) { if (el.GetType() == typeof(TextBox)) { ((TextBox)(el)).Clear(); } if (el.GetType() == typeof(ComboBox)) { ((ComboBox)(el)).SelectedIndex = -1; } } foreach (UIElement el in SoftwareInfoGrid.Children) { if (el.GetType() == typeof(TextBox)) { ((TextBox)(el)).Clear(); } if (el.GetType() == typeof(ComboBox)) { ((ComboBox)(el)).SelectedIndex = -1; } } Ginfo.Clear(); Pinfo.Clear(); ClearRemoteSessionScreen(); RemoteSessionListBox.Items.Clear(); TemplatePreviewBox.Clear(); BlankField.Clear(); } }