コード例 #1
0
        public ViewInspectorViewModel(ClientSession session)
        {
            Session = session;

            Session?.Subscribe(this);

            RootModel = InspectTreeRoot.CreateRoot(this);

            RefreshVisualTreeCommand = new DelegateCommand(
                RefreshVisualTree,
                p => !IsVisualTreeRefreshing);

            ShowPaneCommand = new DelegateCommand(p => {
                if (int.TryParse(p.ToString(), out var pane))
                {
                    SelectedPane = pane;
                }
            });
        }
コード例 #2
0
        public static InspectTreeRoot CreateRoot(ViewInspectorViewModel model)
        {
            var tree = new InspectTreeRoot(model);

            void ModelPropertyChanged(object sender, PropertyChangedEventArgs args)
            {
                var viewModel = sender as ViewInspectorViewModel;

                switch (args.PropertyName)
                {
                case nameof(ViewInspectorViewModel.RootView):
                    if (tree.RootNode?.View == viewModel.RootView)
                    {
                        return;
                    }

                    tree.RootNode = new InspectTreeNode(null, viewModel.RootView);
                    break;

                case nameof(ViewInspectorViewModel.RepresentedView):
                    InspectTreeNode found = null;
                    if (tree.RepresentedNode?.View == viewModel.RepresentedView)
                    {
                        return;
                    }

                    foreach (var node in tree.RootNode.TraverseTree <TreeNode> (n => n.Children))
                    {
                        if (node.RepresentedObject == viewModel.RepresentedView)
                        {
                            found = node as InspectTreeNode;
                            break;
                        }
                    }
                    tree.RepresentedNode = found;
                    break;

                case nameof(ViewInspectorViewModel.SelectedView):
                    if (tree.selectedNode?.View == viewModel.SelectedView)
                    {
                        return;
                    }

                    foreach (var node in tree.RootNode.TraverseTree <TreeNode> (n => n.Children))
                    {
                        var selected = node.RepresentedObject == viewModel.SelectedView;
                        node.IsSelected = selected;
                        if (node.IsSelected)
                        {
                            tree.SelectedNode = node as InspectTreeNode;
                            var parent = (node as InspectTreeNode).Parent;
                            while (parent != null)
                            {
                                parent.IsExpanded = true;
                                parent            = parent.Parent;
                            }
                        }
                    }
                    break;

                case nameof(ViewInspectorViewModel.RenderingDepth):
                case nameof(ViewInspectorViewModel.DisplayMode):
                case nameof(ViewInspectorViewModel.ShowHidden):
                    break;
                }
            }

            model.PropertyChanged += ModelPropertyChanged;
            return(tree);
        }