Example #1
0
        private void DrawerCode_OnOpened(object sender, RoutedEventArgs e)
        {
            var typeKey = ViewModelLocator.Instance.Main.DemoInfoCurrent.Key;
            var demoKey = ViewModelLocator.Instance.Main.DemoItemCurrent.TargetCtlName;

            if (Equals(_currentDemoKey, demoKey))
            {
                return;
            }
            _currentDemoKey = demoKey;

            if (ViewModelLocator.Instance.Main.SubContent is FrameworkElement demoCtl)
            {
                var demoCtlTypeName = demoCtl.GetType().Name;
                var xamlPath        = $"UserControl/{typeKey}/{demoCtlTypeName}.xaml";
                var dc         = demoCtl.DataContext;
                var dcTypeName = dc.GetType().Name;
                var vmPath     = !Equals(dcTypeName, demoCtlTypeName)
                    ? $"ViewModel/{dcTypeName}"
                    : xamlPath;

                EditorXaml.Text = DemoHelper.GetCode(xamlPath);
                EditorCs.Text   = DemoHelper.GetCode($"{xamlPath}.cs");
                EditorVm.Text   = DemoHelper.GetCode($"{vmPath}.cs");
            }
        }
Example #2
0
        private void DrawerCode_OnOpened(object sender, RoutedEventArgs e)
        {
            if (!_drawerCodeUsed)
            {
                var textEditorCustomStyle = ResourceHelper.GetResource <Style>("TextEditorCustom");
                _textEditor = new Dictionary <string, TextEditor>
                {
                    ["XAML"] = new TextEditor
                    {
                        Style = textEditorCustomStyle,
                        SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML")
                    },
                    ["C#"] = new TextEditor
                    {
                        Style = textEditorCustomStyle,
                        SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#")
                    },
                    ["VM"] = new TextEditor
                    {
                        Style = textEditorCustomStyle,
                        SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#")
                    }
                };
                BorderCode.Child = new TabControl
                {
                    Style = ResourceHelper.GetResource <Style>("TabControlInLine"),
                    Items =
                    {
                        new TabItem
                        {
                            Header  = "XAML",
                            Content = _textEditor["XAML"]
                        },
                        new TabItem
                        {
                            Header  = "C#",
                            Content = _textEditor["C#"]
                        },
                        new TabItem
                        {
                            Header  = "VM",
                            Content = _textEditor["VM"]
                        }
                    }
                };

                _drawerCodeUsed = true;
            }

            var typeKey = ViewModelLocator.Instance.Main.DemoInfoCurrent.Key;
            var demoKey = ViewModelLocator.Instance.Main.DemoItemCurrent.TargetCtlName;

            if (Equals(_currentDemoKey, demoKey))
            {
                return;
            }
            _currentDemoKey = demoKey;

            if (ViewModelLocator.Instance.Main.SubContent is FrameworkElement demoCtl)
            {
                var demoCtlTypeName = demoCtl.GetType().Name;
                var xamlPath        = $"UserControl/{typeKey}/{demoCtlTypeName}.xaml";
                var dc         = demoCtl.DataContext;
                var dcTypeName = dc.GetType().Name;
                var vmPath     = !Equals(dcTypeName, demoCtlTypeName)
                    ? $"ViewModel/{dcTypeName}"
                    : xamlPath;

                _textEditor["XAML"].Text = DemoHelper.GetCode(xamlPath);
                _textEditor["C#"].Text   = DemoHelper.GetCode($"{xamlPath}.cs");
                _textEditor["VM"].Text   = DemoHelper.GetCode($"{vmPath}.cs");
            }
        }