コード例 #1
0
        void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (sender == null || e.PropertyName == "Width" || e.PropertyName == "Height")
            {
                AdornerPanel.SetPlacement(thumb1,
                                          new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top)
                {
                    YOffset = 0,
                    XOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Width / 4
                });

                AdornerPanel.SetPlacement(thumb2,
                                          new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center)
                {
                    YOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Height / 4,
                    XOffset = 0
                });

                var designPanel = this.ExtendedItem.Services.DesignPanel as DesignPanel;
                if (designPanel != null)
                {
                    designPanel.AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true);
                }
            }
        }
コード例 #2
0
        public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)
        {
            if (item.View == null)
            {
                return(Rect.Empty);
            }
            var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View);

            return(new Rect(p, PlacementOperation.GetRealElementSize(item.View)));
        }
コード例 #3
0
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            AdornerPanel parent = this.Parent as AdornerPanel;

            if (parent != null && parent.AdornedElement != null)
            {
                if (checkWidth)
                {
                    this.ThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Width > 14;
                }
                else if (checkHeight)
                {
                    this.ThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14;
                }
            }
            return(base.ArrangeOverride(arrangeBounds));
        }
コード例 #4
0
ファイル: AdornerPanel.cs プロジェクト: wskjava/SharpDevelop
        /// <summary/>
        protected override Size MeasureOverride(Size availableSize)
        {
            if (this.AdornedElement != null)
            {
                foreach (DependencyObject v in base.InternalChildren)
                {
                    UIElement e = v as UIElement;
                    if (e != null)
                    {
                        e.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    }
                }

                return(PlacementOperation.GetRealElementSize(this.AdornedElement));
            }
            else
            {
                return(base.MeasureOverride(availableSize));
            }
        }
コード例 #5
0
        public override Rect GetPosition(PlacementOperation operation, DesignItem item)
        {
            UIElement child = item.View;

            if (child == null)
            {
                return(Rect.Empty);
            }

            double x, y;

            if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty))
            {
                x = GetCanvasProperty(child, Canvas.LeftProperty);
            }
            else
            {
                x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) -
                    PlacementOperation.GetRealElementSize(child).Width;
            }


            if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty))
            {
                y = GetCanvasProperty(child, Canvas.TopProperty);
            }
            else
            {
                y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) -
                    PlacementOperation.GetRealElementSize(child).Height;
            }

            var p = new Point(x, y);

            //Fixes, Empty Image Resized to 0
            //return new Rect(p, child.RenderSize);
            return(new Rect(p, PlacementOperation.GetRealElementSize(item.View)));
        }
コード例 #6
0
ファイル: Converters.cs プロジェクト: wskjava/SharpDevelop
 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
 {
     return(PlacementOperation.GetRealElementSize((UIElement)values[0]).Height);
 }
コード例 #7
0
        /// <summary>
        /// Binds the <see cref="MarginHandle.HandleLength"/> to the margin and place the handles.
        /// </summary>
        void BindAndPlaceHandle()
        {
            if (!adornerPanel.Children.Contains(this))
            {
                adornerPanel.Children.Add(this);
            }
            if (!adornerPanel.Children.Contains(Stub))
            {
                adornerPanel.Children.Add(Stub);
            }
            RelativePlacement placement = new RelativePlacement();

            switch (orientation)
            {
            case HandleOrientation.Left:
            {
                var wr = (double)leftDescriptor.GetValue(adornedControl);
                if (double.IsNaN(wr))
                {
                    wr = (double)rightDescriptor.GetValue(adornedControl);
                    wr = canvas.ActualWidth - (PlacementOperation.GetRealElementSize(adornedControl).Width + wr);
                }
                else
                {
                    if (line1 != null)
                    {
                        line1.StrokeDashArray.Clear();
                        line2.StrokeDashArray.Clear();
                    }
                }
                this.HandleLength = wr;
                placement         = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center);
                placement.XOffset = -HandleLengthOffset;
                break;
            }

            case HandleOrientation.Top:
            {
                var wr = (double)topDescriptor.GetValue(adornedControl);
                if (double.IsNaN(wr))
                {
                    wr = (double)bottomDescriptor.GetValue(adornedControl);
                    wr = canvas.ActualHeight - (PlacementOperation.GetRealElementSize(adornedControl).Height + wr);
                }
                else
                {
                    if (line1 != null)
                    {
                        line1.StrokeDashArray.Clear();
                        line2.StrokeDashArray.Clear();
                    }
                }
                this.HandleLength = wr;
                placement         = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top);
                placement.YOffset = -HandleLengthOffset;
                break;
            }

            case HandleOrientation.Right:
            {
                var wr = (double)rightDescriptor.GetValue(adornedControl);
                if (double.IsNaN(wr))
                {
                    wr = (double)leftDescriptor.GetValue(adornedControl);
                    wr = canvas.ActualWidth - (PlacementOperation.GetRealElementSize(adornedControl).Width + wr);
                }
                else
                {
                    if (line1 != null)
                    {
                        line1.StrokeDashArray.Clear();
                        line2.StrokeDashArray.Clear();
                    }
                }
                this.HandleLength = wr;
                placement         = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Center);
                placement.XOffset = HandleLengthOffset;
                break;
            }

            case HandleOrientation.Bottom:
            {
                var wr = (double)bottomDescriptor.GetValue(adornedControl);
                if (double.IsNaN(wr))
                {
                    wr = (double)topDescriptor.GetValue(adornedControl);
                    wr = canvas.ActualHeight - (PlacementOperation.GetRealElementSize(adornedControl).Height + wr);
                }
                else
                {
                    if (line1 != null)
                    {
                        line1.StrokeDashArray.Clear();
                        line2.StrokeDashArray.Clear();
                    }
                }
                this.HandleLength = wr;
                placement         = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Bottom);
                placement.YOffset = HandleLengthOffset;
                break;
            }
            }

            AdornerPanel.SetPlacement(this, placement);
            this.Visibility = Visibility.Visible;
        }
コード例 #8
0
        private void OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            var row     = (int)this.ExtendedItem.Properties.GetAttachedProperty(Grid.RowProperty).ValueOnInstance;
            var rowSpan = (int)this.ExtendedItem.Properties.GetAttachedProperty(Grid.RowSpanProperty).ValueOnInstance;

            var column     = (int)this.ExtendedItem.Properties.GetAttachedProperty(Grid.ColumnProperty).ValueOnInstance;
            var columnSpan = (int)this.ExtendedItem.Properties.GetAttachedProperty(Grid.ColumnSpanProperty).ValueOnInstance;

            var margin = (Thickness)this.ExtendedItem.Properties[FrameworkElement.MarginProperty].ValueOnInstance;

            var          point    = this.ExtendedItem.View.TranslatePoint(new Point(), _grid);
            var          position = new Rect(point, PlacementOperation.GetRealElementSize(this.ExtendedItem.View));
            MarginHandle handle   = null;

            if (sender is MarginHandle)
            {
                handle = sender as MarginHandle;
            }
            if (sender is MarginStub)
            {
                handle = ((MarginStub)sender).Handle;
            }
            if (handle != null)
            {
                switch (handle.Orientation)
                {
                case HandleOrientation.Left:
                    if (_rightHandle.Visibility == Visibility.Visible)
                    {
                        if (_leftHandle.Visibility == Visibility.Visible)
                        {
                            margin.Left = 0;
                            this.ExtendedItem.Properties[FrameworkElement.WidthProperty].SetValue(position.Width);
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Right);
                        }
                        else
                        {
                            var leftMargin = position.Left - GetColumnOffset(column);
                            margin.Left = leftMargin;
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
                            this.ExtendedItem.Properties[FrameworkElement.WidthProperty].Reset();
                        }
                    }
                    else
                    {
                        if (_leftHandle.Visibility == Visibility.Visible)
                        {
                            margin.Left = 0;
                            var rightMargin = GetColumnOffset(column + columnSpan) - position.Right;
                            margin.Right = rightMargin;

                            this.ExtendedItem.Properties[FrameworkElement.WidthProperty].SetValue(position.Width);
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Right);
                        }
                        else
                        {
                            var leftMargin = position.Left - GetColumnOffset(column);
                            margin.Left = leftMargin;
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Left);
                        }
                    }
                    break;

                case HandleOrientation.Top:
                    if (_bottomHandle.Visibility == Visibility.Visible)
                    {
                        if (_topHandle.Visibility == Visibility.Visible)
                        {
                            margin.Top = 0;
                            this.ExtendedItem.Properties[FrameworkElement.HeightProperty].SetValue(position.Height);
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Bottom);
                        }
                        else
                        {
                            var topMargin = position.Top - GetRowOffset(row);
                            margin.Top = topMargin;
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
                            this.ExtendedItem.Properties[FrameworkElement.HeightProperty].Reset();
                        }
                    }
                    else
                    {
                        if (_topHandle.Visibility == Visibility.Visible)
                        {
                            margin.Top = 0;
                            var bottomMargin = GetRowOffset(row + rowSpan) - position.Bottom;
                            margin.Bottom = bottomMargin;

                            this.ExtendedItem.Properties[FrameworkElement.HeightProperty].SetValue(position.Height);
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Bottom);
                        }
                        else
                        {
                            var topMargin = position.Top - GetRowOffset(row);
                            margin.Top = topMargin;
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Top);
                        }
                    }
                    break;

                case HandleOrientation.Right:
                    if (_leftHandle.Visibility == Visibility.Visible)
                    {
                        if (_rightHandle.Visibility == Visibility.Visible)
                        {
                            margin.Right = 0;
                            this.ExtendedItem.Properties[FrameworkElement.WidthProperty].SetValue(position.Width);
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Left);
                        }
                        else
                        {
                            var rightMargin = GetColumnOffset(column + columnSpan) - position.Right;
                            margin.Right = rightMargin;
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
                            this.ExtendedItem.Properties[FrameworkElement.WidthProperty].Reset();
                        }
                    }
                    else
                    {
                        if (_rightHandle.Visibility == Visibility.Visible)
                        {
                            margin.Right = 0;
                            var leftMargin = position.Left - GetColumnOffset(column);
                            margin.Left = leftMargin;

                            this.ExtendedItem.Properties[FrameworkElement.WidthProperty].SetValue(position.Width);
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Left);
                        }
                        else
                        {
                            var rightMargin = GetColumnOffset(column + columnSpan) - position.Right;
                            margin.Right = rightMargin;
                            this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Right);
                        }
                    }
                    break;

                case HandleOrientation.Bottom:
                    if (_topHandle.Visibility == Visibility.Visible)
                    {
                        if (_bottomHandle.Visibility == Visibility.Visible)
                        {
                            margin.Bottom = 0;
                            this.ExtendedItem.Properties[FrameworkElement.HeightProperty].SetValue(position.Height);
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Top);
                        }
                        else
                        {
                            var bottomMargin = GetRowOffset(row + rowSpan) - position.Bottom;
                            margin.Bottom = bottomMargin;
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
                            this.ExtendedItem.Properties[FrameworkElement.HeightProperty].Reset();
                        }
                    }
                    else
                    {
                        if (_bottomHandle.Visibility == Visibility.Visible)
                        {
                            margin.Bottom = 0;
                            var topMargin = position.Top - GetRowOffset(row);
                            margin.Top = topMargin;

                            this.ExtendedItem.Properties[FrameworkElement.HeightProperty].SetValue(position.Height);
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Top);
                        }
                        else
                        {
                            var bottomMargin = GetRowOffset(row + rowSpan) - position.Bottom;
                            margin.Bottom = bottomMargin;
                            this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Bottom);
                        }
                    }
                    break;
                }
            }
            this.ExtendedItem.Properties[FrameworkElement.MarginProperty].SetValue(margin);
        }