private void OnWorkspaceUnloaded(object sender, RoutedEventArgs e) { // stop monitoring input InputManager.Current.PreProcessInput -= OnPreProcessInput; _crackRootVisual = null; // stop monitoring selection changes in the TreeView Tree.SelectedItemChanged -= OnTreeSelectionChanged; // release the viewmodel ViewModel = null; }
private void OnWorkspaceLoaded(object sender, RoutedEventArgs e) { // store a reference to the ViewModel for easy access ViewModel = DataContext as ElementTreeExplorerViewModel; // monitor selection changes in the TreeView Tree.SelectedItemChanged += OnTreeSelectionChanged; // monitor input to catch the Shift+Ctrl modifiers _crackRootVisual = PresentationSource.FromVisual(this).RootVisual; InputManager.Current.PreProcessInput += OnPreProcessInput; // if the root has not been set, locate and inspect the application's root if (ViewModel.Root == null) { object root = null; if (Application.Current != null && Application.Current.MainWindow != null) { root = Application.Current; } else { foreach (PresentationSource presentationSource in PresentationSource.CurrentSources) { if (presentationSource.RootVisual != null) { root = presentationSource.RootVisual; break; } } } if (root != null) { ViewModel.Inspect(root); } } }