Exemple #1
0
        /// <summary>
        /// Centers the view on a node by changing the workspace's CurrentOffset.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void CenterViewOnElement(object sender, EventArgs e)
        {
            this.Dispatcher.BeginInvoke((Action) delegate
            {
                var vm = (DataContext as WorkspaceViewModel);

                var n = (e as ModelEventArgs).Model;

                if (workBench != null)
                {
                    var b = workBench.TransformToAncestor(outerCanvas);

                    Point outerCenter         = new Point(outerCanvas.ActualWidth / 2, outerCanvas.ActualHeight / 2);
                    Point nodeCenterInCanvas  = new Point(n.X + n.Width / 2, n.Y + n.Height / 2);
                    Point nodeCenterInOverlay = b.Transform(nodeCenterInCanvas);

                    double deltaX = nodeCenterInOverlay.X - outerCenter.X;
                    double deltaY = nodeCenterInOverlay.Y - outerCenter.Y;

                    //var offset = new Point(vm.CurrentOffset.X - deltaX, vm.CurrentOffset.Y - deltaY);

                    //vm.CurrentOffset = offset;

                    zoomBorder.SetTranslateTransformOrigin(new Point2D(vm.Model.X - deltaX, vm.Model.Y - deltaY));
                }
            });
        }