public static WpfElement BuildWpfElement(XElement parent) { var hasUnprocessedChildren = parent.HasElements; var element = new WpfElement(); element.Name = new StringWrapper(parent.GetXAttribute("Name")); element.ObjectType = Type.GetType(parent.Name.LocalName); //Populate events foreach (var eventInfo in element.ObjectType.GetEvents() ) { element.Events.Add(eventInfo.Name, null); } //process children if they exist and have not yet been processed if (parent.HasElements && hasUnprocessedChildren) { foreach (var child in parent.Elements()) { element.Children.Add(BuildWpfElement(child)); } } //parent contains no unprocessed children hasUnprocessedChildren = true; return element; }
public static void ImportXaml(XDocument file, WpfElement parent, bool loadAllElements = false) { //file.Root.RecursivelyProcess(ProcessChild, null, null, parent, loadAllElements);//ProcessParentClose //ProcessParentOpen }
public WpfElement LoadXaml(XDocument document) { var element = new WpfElement(); // ImportXaml(document, element); return element; }
private void button_Browse_Click(object sender, RoutedEventArgs e) { // Create OpenFileDialog var dlg = new OpenFileDialog {DefaultExt = ".xaml"}; // Display OpenFileDialog by calling ShowDialog method var result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result != true) return; // Open document XamlPath = dlg.FileName; var xaml = new WpfElement(); WpfElement.ImportXaml(XDocument.Load(new FileStream(XamlPath, FileMode.Open)), xaml); XamlFilePaths.Add(new StringWrapper(XamlPath)); dataGrid_XamlFilePaths.ItemsSource = XamlFilePaths; }