Exemplo n.º 1
0
        private void UpdateDisplayTabs(object o, object o1)
        {
            Exception exception = null;

            try
            {
                if (o == MainTab && MainTab.SelectedItem == PanelTab)
                {
                    TabControl.SelectedItem = TabCoreXaml;
                }

                var selectedItem = TabControl.SelectedItem as TabItem;
                switch (selectedItem?.Header.ToString())
                {
                case "CoreXaml":
                    var 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;
            }

            OnError(exception);
        }
Exemplo n.º 2
0
        private void ParsingXaml(object sender, RoutedEventArgs e)
        {
            var item = sender as MenuItem;

            try
            {
                var 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":
                    var 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 += 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);
            }
        }