void OnDesignerViewUnloaded(object sender, RoutedEventArgs e)
 {
     if (this.scrollViewerPanner != null)
     {
         this.scrollViewerPanner.ScrollViewer = null;
         this.scrollViewerPanner = null;
     }
 }
        void OnDesignerViewLoaded(object sender, RoutedEventArgs e)
        {
            ViewStateService viewStateService = this.Context.Services.GetService<ViewStateService>();
            ModelTreeManager modelTreeManager = this.context.Services.GetService<ModelTreeManager>();
            //Initialize ShouldExpandAll if it exists in ViewState.
            object expandAllState = viewStateService.RetrieveViewState(modelTreeManager.Root, DesignerView.ShouldExpandAllProperty.Name);
            if (expandAllState != null)
            {
                this.ShouldExpandAll = (bool)expandAllState;
            }
            if (!this.ShouldExpandAll)
            {
                object collapseAllState = viewStateService.RetrieveViewState(modelTreeManager.Root, DesignerView.ShouldCollapseAllProperty.Name);
                if (collapseAllState != null)
                {
                    this.ShouldCollapseAll = (bool)collapseAllState;
                }
            }
            // SQM: Open Minimap through designer surface
            this.buttonMinimap.Checked += new RoutedEventHandler(SqmOpenMinimap);
            this.expandAllButton.Click += new RoutedEventHandler(SqmExpandAll);
            this.collapseAllButton.Click += new RoutedEventHandler(SqmCollapseAll);

            if (this.IsPanModeEnabled)
            {
                this.scrollViewerPanner = new ScrollViewerPanner(this.ScrollViewer);
                this.scrollViewerPanner.Hand = (Cursor)this.Resources["ReadyToPanCursor"];
                this.scrollViewerPanner.DraggingHand = (Cursor)this.Resources["PanningCursor"];
            }
        }