Example #1
0
        /// <summary>
        /// Implements any custom measuring behavior for the adorner.
        /// </summary>
        /// <param name="constraint">A size to constrain the adorner to.</param>
        /// <returns>
        /// A <see cref="T:System.Windows.Size" /> object representing the amount of layout space needed by the adorner.
        /// </returns>
        protected override Size MeasureOverride(Size constraint)
        {
            AdornedElement.Measure(constraint);
            _textBox.Measure(constraint);

            // since the adorner has to cover the TextBlock, it should return
            // the AdornedElement.Width, the extra 15 is to make it more clear.
            return(new Size(Math.Max(_textBox.DesiredSize.Width, AdornedElement.DesiredSize.Width), Math.Max(_textBox.DesiredSize.Height, AdornedElement.DesiredSize.Height)));
        }
Example #2
0
        /// <summary>
        /// Override to measure elements.
        /// </summary>
        protected override Size MeasureOverride(Size constraint)
        {
            _TextBox.IsEnabled = _IsVisible;

            // if in editing mode, measure the space the adorner element should cover.
            if (_IsVisible == true)
            {
                if (double.IsInfinity(_TextBoxMaxWidth) == true)
                {
                    Point position        = _TextBox.PointToScreen(new Point(0, 0)),
                          controlPosition = _EditBox.ParentScrollViewer.PointToScreen(new Point(0, 0));

                    position.X = Math.Abs(controlPosition.X - position.X);
                    position.Y = Math.Abs(controlPosition.Y - position.Y);

                    _TextBoxMaxWidth = _EditBox.ParentScrollViewer.ViewportWidth - position.X;
                }

                if (this.AdornedElement.Visibility == System.Windows.Visibility.Collapsed)
                {
                    return(new Size(_TextBoxMaxWidth, _TextBox.DesiredSize.Height));
                }

                //
                if (constraint.Width > _TextBoxMaxWidth)
                {
                    constraint.Width = _TextBoxMaxWidth;
                }

                AdornedElement.Measure(constraint);
                _TextBox.Measure(constraint);

                double desiredWidth = AdornedElement.DesiredSize.Width + ExtraWidth;

                // since the adorner is to cover the EditBox, it should return
                // the AdornedElement.Width, the extra 15 is to make it more clear.
                if (desiredWidth < _TextBoxMaxWidth)
                {
                    return(new Size(desiredWidth, _TextBox.DesiredSize.Height));
                }
                else
                {
                    this.AdornedElement.Visibility = System.Windows.Visibility.Collapsed;

                    return(new Size(_TextBoxMaxWidth, _TextBox.DesiredSize.Height));
                }
            }
            else  // no need to show anything if it is not in editable mode.
            {
                return(new Size(0, 0));
            }
        }
Example #3
0
        private void HandleBottomRight(object sender, DragDeltaEventArgs eventArgs)
        {
            var thumb   = sender as Thumb;
            var element = AdornedElement as FrameworkElement;

            if (element == null || thumb == null)
            {
                return;
            }

            element.MaxWidth  = Math.Max(element.MaxWidth + eventArgs.HorizontalChange, thumb.DesiredSize.Width);
            element.MaxHeight = Math.Max(element.MaxHeight + eventArgs.VerticalChange, thumb.DesiredSize.Height);
            var size = new Size(element.MaxWidth, element.MaxHeight);

            AdornedElement.Measure(size);
        }
Example #4
0
        /// <summary>
        ///     Override to measure elements.
        /// </summary>
        protected override Size MeasureOverride(Size constraint)
        {
            mTextBox.IsEnabled = mIsVisible;

            // if in editing mode, measure the space the adorner element should cover.
            if (mIsVisible)
            {
                if (double.IsInfinity(mTextBoxMaxWidth))
                {
                    Point position        = mTextBox.PointToScreen(new Point(0, 0)),
                          controlPosition = mEditBox.ParentScrollViewer.PointToScreen(new Point(0, 0));

                    position.X = Math.Abs(controlPosition.X - position.X);
                    position.Y = Math.Abs(controlPosition.Y - position.Y);

                    mTextBoxMaxWidth = mEditBox.ParentScrollViewer.ViewportWidth - position.X;
                }

                if (AdornedElement.Visibility == Visibility.Collapsed)
                {
                    return(new Size(mTextBoxMaxWidth, mTextBox.DesiredSize.Height));
                }

                //
                if (constraint.Width > mTextBoxMaxWidth)
                {
                    constraint.Width = mTextBoxMaxWidth;
                }

                AdornedElement.Measure(constraint);
                mTextBox.Measure(constraint);

                var desiredWidth = AdornedElement.DesiredSize.Width + ExtraWidth;

                // since the adorner is to cover the EditBox, it should return
                // the AdornedElement.Width, the extra 15 is to make it more clear.
                if (desiredWidth < mTextBoxMaxWidth)
                {
                    return(new Size(desiredWidth, mTextBox.DesiredSize.Height));
                }
                AdornedElement.Visibility = Visibility.Collapsed;

                return(new Size(mTextBoxMaxWidth, mTextBox.DesiredSize.Height));
            }
            return(new Size(0, 0));
        }
        /// <summary>
        /// Override to measure elements.
        /// </summary>
        protected override Size MeasureOverride(Size constraint)
        {
            _textBox.IsEnabled = _isVisible;
            //if in editable mode, measure the space the adorner element should cover.
            if (_isVisible)
            {
                AdornedElement.Measure(constraint);
                _textBox.Measure(constraint);

                //since the adorner is to cover the EditBox, it should return the AdornedElement.Width,
                //the extra 15 is to make it more clear.
                return(new Size(AdornedElement.DesiredSize.Width + _extraWidth, _textBox.DesiredSize.Height));
            }
            else  //if it is not in editable mode, no need to show anything.
            {
                return(new Size(0, 0));
            }
        }
Example #6
0
        /// <summary>
        ///     Override to measure elements.
        /// </summary>
        protected override Size MeasureOverride(Size constraint)
        {
            _textBox.IsEnabled = _isVisible;
            //if in editing mode, measure the space the adorner element
            //should cover.
            if (_isVisible)
            {
                AdornedElement.Measure(constraint);
                _textBox.Measure(constraint);

                //since the adorner is to cover the EditBox, it should return
                //the AdornedElement.Width, the extra 15 is to make it more
                //clear.
                return(new Size(AdornedElement.DesiredSize.Width + ExtraWidth,
                                _textBox.DesiredSize.Height));
            }
            return(new Size(0, 0));
        }
        /// <summary>
        ///     Get cropping areas as BitmapFrame
        /// </summary>
        /// <returns></returns>
        public BitmapFrame GetCroppedBitmapFrame()
        {
            var parent = VisualTreeHelper.GetParent(AdornedElement) as UIElement;
            // 1) get current dpi
            var    pSource = PresentationSource.FromVisual(Application.Current.MainWindow);
            Matrix m       = pSource.CompositionTarget.TransformToDevice;
            double dpiX    = m.M11 * 96;
            double dpiY    = m.M22 * 96;

            // 2) create RenderTargetBitmap
            var elementBitmap = new RenderTargetBitmap(
                (int)AdornedElement.RenderSize.Width,
                (int)AdornedElement.RenderSize.Height,
                dpiX,
                dpiY,
                PixelFormats.Default
                );

            //Important
            AdornedElement.Measure(AdornedElement.RenderSize);
            AdornedElement.Arrange(new Rect(AdornedElement.RenderSize));

            // 3) draw element
            elementBitmap.Render(AdornedElement);

            if (parent != null)
            {
                //Important
                parent.Measure(AdornedElement.RenderSize);
                parent.Arrange(new Rect(AdornedElement.RenderSize));
            }

            var crop = new CroppedBitmap(
                elementBitmap,
                new Int32Rect(
                    (int)_rectangleManager.TopLeft.X,
                    (int)_rectangleManager.TopLeft.Y,
                    (int)_rectangleManager.RectangleWidth,
                    (int)_rectangleManager.RectangleHeight
                    )
                );

            return(BitmapFrame.Create(crop));
        }
Example #8
0
        /// <summary>
        /// Implements any custom measuring behavior for the adorner.
        /// </summary>
        /// <param name="constraint">A size to constrain the adorner to.</param>
        /// <returns>
        /// A <see cref="Size"/> object representing the amount of layout space needed by the
        /// adorner.
        /// </returns>
        protected override Size MeasureOverride(Size constraint)
        {
            AdornedElement.Measure(constraint);
            _textBox.Measure(constraint);

            // Determine width of TextBox.
            // Minimal width is defined by the adorned element.
            // Maximal width is defined by 'constraint'.
            double width = Math.Max(AdornedElement.DesiredSize.Width + ExtraWidth, _textBox.DesiredSize.Width + ExtraWidth);

            width = Math.Min(width, constraint.Width);

            // Determine height of TextBox.
            // Minimal height is defined by the adorned element.
            // Maximal width is defined by 'constraint'.
            double height = Math.Max(AdornedElement.DesiredSize.Height + 2 * TextBoxBorder, _textBox.DesiredSize.Height);

            height = Math.Min(height, constraint.Height);
            return(new Size(width, height));
        }
Example #9
0
        /// <summary>
        ///     Override to measure elements.
        /// </summary>
        protected override Size MeasureOverride(Size constraint)
        {
            _textBox.IsEnabled = _isVisible;
            //if in editing mode, measure the space the adorner element
            //should cover.
            if (_isVisible)
            {
                AdornedElement.Measure(constraint);
                _textBox.Measure(constraint);

                // Gets the ActualWidth of the EditBox so the TextBox
                // doesn't cover further than the TextBlock and the buttons
                // remain visible
                var adornedElement = this.AdornedElement as TextBlock;
                var editBox        = adornedElement.TemplatedParent as Control;
                var actualWdith    = editBox.ActualWidth;

                return(new Size(actualWdith, _textBox.DesiredSize.Height));
            }
            return(new Size(0, 0));
        }
Example #10
0
 /**
  * @brief Calculates the final size of the adorner.
  * @param[in] constraints (Size) The constraints the adorner must to adhere to.
  * @return (Size) Final size of the adorner.
  */
 protected override Size MeasureOverride(Size constraint)
 {
     AdornedElement.Measure(constraint);
     textbox_.Measure(constraint);
     return(new Size(AdornedElement.DesiredSize.Width + 15, textbox_.DesiredSize.Height));
 }
Example #11
0
 protected override Size MeasureOverride(Size constraint)
 {
     AdornedElement.Measure(constraint);
     InvalidateVisual();
     return(new Size(Bounds.Width + _topLeft.Width + _topRight.Width, Bounds.Height + _bottomLeft.Height + (3 * _rotate.Height)));;
 }
Example #12
0
        private UIElementCollection children; //!< Visual children of the adorner. These children represent the different docking options.

        /**
         * @brief Calculates the final size of the adorner.
         * @param[in] constraints (Size) The constraints the adorner must to adhere to.
         * @return (Size) Final size of the adorner.
         */
        protected override Size MeasureOverride(Size constraint)
        {
            AdornedElement.Measure(constraint);
            return(AdornedElement.RenderSize);
        }