void UpdateDisplayTabs(object o, object o1) { Exception exception = null; try { if (o == MainTab && MainTab.SelectedItem == PanelTab) { TabControl.SelectedItem = TabCoreXaml; } TabItem selectedItem = TabControl.SelectedItem as TabItem; switch (selectedItem.Header.ToString()) { case "CoreXaml": TextRange range = new TextRange(CoreXaml.Document.ContentEnd, CoreXaml.Document.ContentStart); if (((TabItem)MainTab.SelectedItem).Header.ToString() == "RichTextBox") { XamlHelper.TextRange_SetXml(range, XamlHelper.ColoringXaml(XamlHelper.IndentXaml(XamlWriter.Save(MainEditor.Document)))); } else if (((TabItem)MainTab.SelectedItem).Header.ToString() == "Panel") { XamlHelper.TextRange_SetXml(range, XamlHelper.ColoringXaml(XamlHelper.IndentXaml(XamlWriter.Save(PanelTab.Content)))); } break; case "SelectionXaml": SelectionXaml.Text = XamlHelper.IndentXaml(XamlHelper.TextRange_GetXml(MainEditor.Selection)); break; case "TextSerializedXaml": TextSerializedXaml.Text = XamlHelper.IndentXaml(XamlHelper.TextRange_GetXml(new TextRange(MainEditor.Document.ContentEnd, MainEditor.Document.ContentStart))); break; case "DocumentTree": TreeViewhelper.SetupTreeView(TextTreeView, MainEditor.Document); break; default: OnError(new Exception("Can't find specified TabItem!")); break; } } catch (Exception e) { exception = e; } if (exception == null) { OnError(null); } else { OnError(exception); } }
void ParsingXaml(object sender, RoutedEventArgs e) { MenuItem item = sender as MenuItem; try { string xaml = ""; switch (item.Header.ToString()) { case "SelectionXaml": xaml = XamlHelper.RemoveIndentation(TextSerializedXaml.Text); XamlHelper.TextRange_SetXml(MainEditor.Selection, xaml); break; case "TextSerializedXaml": xaml = XamlHelper.RemoveIndentation(TextSerializedXaml.Text); XamlHelper.TextRange_SetXml(new TextRange(MainEditor.Document.ContentEnd, MainEditor.Document.ContentStart), xaml); break; case "CoreXaml": TextRange range = new TextRange(CoreXaml.Document.ContentEnd, CoreXaml.Document.ContentStart); xaml = XamlHelper.RemoveIndentation(range.Text); if (((TabItem)MainTab.SelectedItem).Header.ToString() == "RichTextBox") { MainEditor.Document = (FlowDocument)XamlHelper.ParseXaml(xaml); MainEditor.Selection.Changed += new EventHandler(UpdateDisplayTabs); RefreshTable(); } else if (((TabItem)MainTab.SelectedItem).Header.ToString() == "Panel") { ((TabItem)MainTab.SelectedItem).Content = XamlHelper.ParseXaml(xaml); OnError(null); } break; default: OnError(new Exception("Don't know how to parse the xaml")); break; } } catch (Exception exception) { OnError(exception); } }