Esempio n. 1
0
        void AttachedPropertiesSnippets()
        {
            //<Snippet27>
            InkCanvas.SetTop(button1, 100);
            //</Snippet27>

            //<Snippet28>
            InkCanvas.SetBottom(button1, 100);
            //</Snippet28>

            //<Snippet29>
            InkCanvas.SetLeft(button1, 100);
            //</Snippet29>

            //<Snippet30>
            InkCanvas.SetRight(button1, 100);
            //</Snippet30>

            //<Snippet31>
            double buttonLeft = InkCanvas.GetLeft(button1);
            //</Snippet31>

            //<Snippet32>
            double buttonRight = InkCanvas.GetRight(button1);
            //</Snippet32>

            //<Snippet33>
            double buttonTop = InkCanvas.GetTop(button1);
            //</Snippet33>

            //<Snippet34>
            double buttonBottom = InkCanvas.GetBottom(button1);
            //</Snippet34>
        }
Esempio n. 2
0
        /// <summary>
        /// UpdateElementBounds:
        ///     Called by   InkCanvasSelection.UpdateElementBounds
        ///                 ClipboardProcessor.CopySelectionInXAML
        /// </summary>
        /// <param name="originalElement"></param>
        /// <param name="updatedElement"></param>
        /// <param name="transform"></param>
        internal void UpdateElementBounds(UIElement originalElement, UIElement updatedElement, Matrix transform)
        {
            if (originalElement.DependencyObjectType.Id == updatedElement.DependencyObjectType.Id)
            {
                // Get the transform from element to Canvas
                GeneralTransform elementToCanvas = originalElement.TransformToAncestor(_inkCanvas.InnerCanvas);

                //cast to a FrameworkElement, nothing inherits from UIElement besides it right now
                FrameworkElement frameworkElement = originalElement as FrameworkElement;
                Size             size;
                Thickness        thickness = new Thickness();
                if (frameworkElement == null)
                {
                    // Get the element's render size.
                    size = originalElement.RenderSize;
                }
                else
                {
                    size      = new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight);
                    thickness = frameworkElement.Margin;
                }

                Rect elementBounds = new Rect(0, 0, size.Width, size.Height);   // Rect in element space
                elementBounds = elementToCanvas.TransformBounds(elementBounds); // Rect in Canvas space

                // Now apply the matrix to the element bounds
                Rect newBounds = Rect.Transform(elementBounds, transform);

                if (!DoubleUtil.AreClose(elementBounds.Width, newBounds.Width))
                {
                    if (frameworkElement == null)
                    {
                        Size newSize = originalElement.RenderSize;
                        newSize.Width             = newBounds.Width;
                        updatedElement.RenderSize = newSize;
                    }
                    else
                    {
                        ((FrameworkElement)updatedElement).Width = newBounds.Width;
                    }
                }

                if (!DoubleUtil.AreClose(elementBounds.Height, newBounds.Height))
                {
                    if (frameworkElement == null)
                    {
                        Size newSize = originalElement.RenderSize;
                        newSize.Height            = newBounds.Height;
                        updatedElement.RenderSize = newSize;
                    }
                    else
                    {
                        ((FrameworkElement)updatedElement).Height = newBounds.Height;
                    }
                }

                double left   = InkCanvas.GetLeft(originalElement);
                double top    = InkCanvas.GetTop(originalElement);
                double right  = InkCanvas.GetRight(originalElement);
                double bottom = InkCanvas.GetBottom(originalElement);

                Point originalPosition = new Point(); // Default as (0, 0)
                if (!double.IsNaN(left))
                {
                    originalPosition.X = left;
                }
                else if (!double.IsNaN(right))
                {
                    originalPosition.X = right;
                }

                if (!double.IsNaN(top))
                {
                    originalPosition.Y = top;
                }
                else if (!double.IsNaN(bottom))
                {
                    originalPosition.Y = bottom;
                }

                Point newPosition = originalPosition * transform;

                if (!double.IsNaN(left))
                {
                    InkCanvas.SetLeft(updatedElement, newPosition.X - thickness.Left);           // Left wasn't auto
                }
                else if (!double.IsNaN(right))
                {
                    // NOTICE-2005/05/05-WAYNEZEN
                    // Canvas.RightProperty means the distance between element right side and its parent Canvas
                    // right side. The same definition is applied to Canvas.BottomProperty
                    InkCanvas.SetRight(updatedElement, (right - (newPosition.X - originalPosition.X)));     // Right wasn't not auto
                }
                else
                {
                    InkCanvas.SetLeft(updatedElement, newPosition.X - thickness.Left);           // Both Left and Right were aut. Modify Left by default.
                }

                if (!double.IsNaN(top))
                {
                    InkCanvas.SetTop(updatedElement, newPosition.Y - thickness.Top);           // Top wasn't auto
                }
                else if (!double.IsNaN(bottom))
                {
                    InkCanvas.SetBottom(updatedElement, (bottom - (newPosition.Y - originalPosition.Y)));          // Bottom wasn't not auto
                }
                else
                {
                    InkCanvas.SetTop(updatedElement, newPosition.Y - thickness.Top);           // Both Top and Bottom were aut. Modify Left by default.
                }
            }
            else
            {
                Debug.Assert(false, "The updatedElement has to be the same type as the originalElement.");
            }
        }
Esempio n. 3
0
 // Token: 0x06006D82 RID: 28034 RVA: 0x001F7060 File Offset: 0x001F5260
 internal void UpdateElementBounds(UIElement originalElement, UIElement updatedElement, Matrix transform)
 {
     if (originalElement.DependencyObjectType.Id == updatedElement.DependencyObjectType.Id)
     {
         GeneralTransform generalTransform = originalElement.TransformToAncestor(this._inkCanvas.InnerCanvas);
         FrameworkElement frameworkElement = originalElement as FrameworkElement;
         Thickness        thickness        = default(Thickness);
         Size             renderSize;
         if (frameworkElement == null)
         {
             renderSize = originalElement.RenderSize;
         }
         else
         {
             renderSize = new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight);
             thickness  = frameworkElement.Margin;
         }
         Rect rect = new Rect(0.0, 0.0, renderSize.Width, renderSize.Height);
         rect = generalTransform.TransformBounds(rect);
         Rect rect2 = Rect.Transform(rect, transform);
         if (!DoubleUtil.AreClose(rect.Width, rect2.Width))
         {
             if (frameworkElement == null)
             {
                 Size renderSize2 = originalElement.RenderSize;
                 renderSize2.Width         = rect2.Width;
                 updatedElement.RenderSize = renderSize2;
             }
             else
             {
                 ((FrameworkElement)updatedElement).Width = rect2.Width;
             }
         }
         if (!DoubleUtil.AreClose(rect.Height, rect2.Height))
         {
             if (frameworkElement == null)
             {
                 Size renderSize3 = originalElement.RenderSize;
                 renderSize3.Height        = rect2.Height;
                 updatedElement.RenderSize = renderSize3;
             }
             else
             {
                 ((FrameworkElement)updatedElement).Height = rect2.Height;
             }
         }
         double left   = InkCanvas.GetLeft(originalElement);
         double top    = InkCanvas.GetTop(originalElement);
         double right  = InkCanvas.GetRight(originalElement);
         double bottom = InkCanvas.GetBottom(originalElement);
         Point  point  = default(Point);
         if (!double.IsNaN(left))
         {
             point.X = left;
         }
         else if (!double.IsNaN(right))
         {
             point.X = right;
         }
         if (!double.IsNaN(top))
         {
             point.Y = top;
         }
         else if (!double.IsNaN(bottom))
         {
             point.Y = bottom;
         }
         Point point2 = point * transform;
         if (!double.IsNaN(left))
         {
             InkCanvas.SetLeft(updatedElement, point2.X - thickness.Left);
         }
         else if (!double.IsNaN(right))
         {
             InkCanvas.SetRight(updatedElement, right - (point2.X - point.X));
         }
         else
         {
             InkCanvas.SetLeft(updatedElement, point2.X - thickness.Left);
         }
         if (!double.IsNaN(top))
         {
             InkCanvas.SetTop(updatedElement, point2.Y - thickness.Top);
             return;
         }
         if (!double.IsNaN(bottom))
         {
             InkCanvas.SetBottom(updatedElement, bottom - (point2.Y - point.Y));
             return;
         }
         InkCanvas.SetTop(updatedElement, point2.Y - thickness.Top);
     }
 }