Exemplo n.º 1
0
        internal void SetWindowPosition(ExtensionWindow window, Point position)
        {
            Func <double, double, double, double, double> CalculateInBoundsValue =
                (pos, size, limit, modifier) =>
            {
                if (this.AutoExpandCanvas)
                {
                    return(pos - modifier);
                }
                else
                {
                    pos = Math.Max(0.0, pos);
                    return(pos + size > limit ? limit - size : pos);
                }
            };

            //in case of AutoExpandCanvas == false:
            // - do not allow placing window outside surface bounds
            //in case of AutoExpandCanvas == true:
            // - include possible negative canvas offset
            position.X = CalculateInBoundsValue(position.X, window.DesiredSize.Width, this.ActualWidth, this.selectedChild.Value.X);
            position.Y = CalculateInBoundsValue(position.Y, window.DesiredSize.Height, this.ActualHeight, this.selectedChild.Value.Y);

            //update its position on canvas
            ExtensionSurface.SetPosition(window, position);

            bool requiresMeasure = false;

            if (this.AutoExpandCanvas)
            {
                requiresMeasure     = true;
                this.canvasOffset.X = 0;
                this.canvasOffset.Y = 0;

                foreach (UIElement item in this.Children)
                {
                    FrameworkElement child = item as FrameworkElement;
                    if (null != child)
                    {
                        Point p = ExtensionSurface.GetPosition(child);
                        this.canvasOffset.X = Math.Min(this.canvasOffset.X, p.X);
                        this.canvasOffset.Y = Math.Min(this.canvasOffset.Y, p.Y);
                    }
                }
                this.canvasOffset.X = Math.Abs(this.canvasOffset.X);
                this.canvasOffset.Y = Math.Abs(this.canvasOffset.Y);
            }
            if (requiresMeasure)
            {
                this.InvalidateMeasure();
            }
            else
            {
                this.InvalidateArrange();
            }
        }
 private void UpdateRubberBand()
 {
     if (this.ExtenstionSurface.Children.Contains(this.rubberBand))
     {
         // Transform the start and end points to be relative to the extension surface by transforming to the common ancestor (DesignerView) first
         GeneralTransform transform1 = this.Designer.scrollableContent.TransformToAncestor(this.Designer);
         GeneralTransform transform2 = this.Designer.TransformToDescendant(this.ExtenstionSurface);
         Point            start      = ClipPoint(transform2.Transform(transform1.Transform(this.StartPoint)));
         Point            end        = ClipPoint(transform2.Transform(transform1.Transform(this.EndPoint)));
         Rect             rect       = new Rect(start, end);
         this.rubberBand.Width  = rect.Width;
         this.rubberBand.Height = rect.Height;
         this.rubberBand.InvalidateVisual();
         ExtensionSurface.SetPosition(this.rubberBand, rect.TopLeft);
     }
     else
     {
         Fx.Assert(false, "Rubber band was not correctly added.");
     }
 }