private void Button_Click(object sender, RoutedEventArgs e) { if (this.list.SelectedItem == null) { return; } FrameworkElement element = null; if (this.list.SelectedIndex == 0) { element = this.button; } else if (this.list.SelectedIndex == 1) { element = this.emf; } else if (this.list.SelectedIndex == 2) { element = this.radioButton; } if (element != null) { StringBuilder b = new StringBuilder(); XamlWriterSettings settings = new XamlWriterSettings(); settings.WriteDefaultValues = this.checkDefault.IsChecked ?? false; using (XamlWriter writer = XamlWriter.CreateWriter(b, this.checkAttributes.IsChecked ?? false, settings)) { writer.WriteElement(element); } result.Text = b.ToString(); } }