当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkElement.TransformToVisual方法代码示例

本文整理汇总了C#中System.Windows.FrameworkElement.TransformToVisual方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.TransformToVisual方法的具体用法?C# FrameworkElement.TransformToVisual怎么用?C# FrameworkElement.TransformToVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.FrameworkElement的用法示例。


在下文中一共展示了FrameworkElement.TransformToVisual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTransformToRoot

 /// <summary>
 /// This method was brought over from core's Transform.cs class to handle
 /// the special cases that can be encountered looking for the root visual
 /// (in Silverlight vs WPF, etc)
 /// </summary>
 internal static GeneralTransform GetTransformToRoot(FrameworkElement child)
 {
     if (Application.Current != null)
     {
         if (child.FlowDirection == FlowDirection.RightToLeft)
             return child.TransformToVisual(null);
         return child.TransformToVisual(Application.Current.RootVisual);
     }
     else
         return child.TransformToVisual(null);
 }
开发者ID:Esri,项目名称:arcgis-viewer-silverlight,代码行数:16,代码来源:Transform.cs

示例2: IsInView

 private static bool IsInView(FrameworkElement element, FrameworkElement container)
 {
     if (element == null || element.Visibility == Visibility.Collapsed) {
     return false;
       }
       var bounds = element.TransformToVisual(container).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight));
       var rect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
       return rect.Contains(new Point(bounds.X, bounds.Y)) || rect.Contains(new Point(bounds.X, bounds.Y + bounds.Height));
 }
开发者ID:alonkrifcher,项目名称:appboy-unity-sdk,代码行数:9,代码来源:Feed.xaml.cs

示例3: AreBoundaryIntersecting

 public override bool AreBoundaryIntersecting(FrameworkElement item)
 {
    RectangleGeometry itemBounds =
        new RectangleGeometry(new Rect(0, 0, item.ActualWidth, item.ActualHeight));
    RectangleGeometry rulerBounds =
        new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight));
    itemBounds.Transform = (Transform)item.TransformToVisual(this);
    return itemBounds.FillContainsWithDetail(rulerBounds) != IntersectionDetail.Empty;
 }
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:9,代码来源:Ruler.cs

示例4: AreBoundaryIntersecting

 public override bool AreBoundaryIntersecting(FrameworkElement cursorVisual)
 {
    RectangleGeometry cursorBounds =
        new RectangleGeometry(new Rect(0, 0, cursorVisual.ActualWidth, cursorVisual.ActualHeight));
    RectangleGeometry targetBounds =
        new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight));
    cursorBounds.Transform = (Transform)cursorVisual.TransformToVisual(this);
    return cursorBounds.FillContainsWithDetail(targetBounds) != IntersectionDetail.Empty;
 }
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:9,代码来源:MagicLens.cs

示例5: getCorners

        public System.Windows.Point[] getCorners(FrameworkElement parent, FrameworkElement child)
        {
            var t = child.TransformToVisual(parent);
            System.Windows.Point topLeft = t.Transform(new System.Windows.Point(0, 0));
            System.Windows.Point topRight = t.Transform(new System.Windows.Point(child.ActualWidth, 0));
            System.Windows.Point bottomLeft = t.Transform(new System.Windows.Point(0, child.ActualHeight));
            System.Windows.Point bottomRight = t.Transform(new System.Windows.Point(child.ActualWidth, child.ActualHeight));

            return new System.Windows.Point[] { topLeft, topRight, bottomLeft, bottomRight };
        }
开发者ID:sunghyunL,项目名称:meetingtable2,代码行数:10,代码来源:PointIn.cs

示例6: GetRelativePosition

 public static Point GetRelativePosition(FrameworkElement e, FrameworkElement relativeTo, Corner p)
 {
     GeneralTransform gt = e.TransformToVisual(relativeTo);
     Point po = new Point();
     if (p == Corner.LeftTop)
         po = gt.Transform(new Point(0, 0));
     if (p == Corner.LeftBottom)
         po = gt.Transform(new Point(0, e.ActualHeight));
     if (p == Corner.RightTop)
         po = gt.Transform(new Point(e.ActualWidth, 0));
     if (p == Corner.RightBottom)
         po = gt.Transform(new Point(e.ActualWidth, e.ActualHeight));
     return po;
 }
开发者ID:nitinr708,项目名称:ProwarenessDashboard,代码行数:14,代码来源:Position.cs

示例7: GetGeneralTransform

        internal static GeneralTransform GetGeneralTransform(FrameworkElement element)
        {
            GeneralTransform transform = null;

#if WPF
            Visual parent = VisualTreeHelper.GetParent(element) as Visual;
            if (parent != null)
            {
                transform = element.TransformToVisual(parent);
            }
            else
            {
                TransformGroup transformGroup = new TransformGroup();
                if (element.LayoutTransform != null)
                {
                    transformGroup.Children.Add(element.LayoutTransform);
                }
                if (element.RenderTransform != null)
                {
                    transformGroup.Children.Add(element.RenderTransform);
                }
                transform = transformGroup;
            }
#elif SILVERLIGHT
            UIElement parent = VisualTreeHelper.GetParent(element) as UIElement;
            if (parent != null)
            {
                transform = element.TransformToVisual(parent);
            }
            else
            {
                transform = element.RenderTransform;
            }
#endif

            return transform;
        }
开发者ID:Motaz-Al-Zoubi,项目名称:xaml-sdk,代码行数:37,代码来源:MathHelper.cs

示例8: GetCollisionsAt

 public static List<UIElement> GetCollisionsAt(FrameworkElement targetelement, Point p, Size pointersize)
 {
     p = targetelement.TransformToVisual(Application.Current.RootVisual).Transform(p);
     Rect r = new Rect(p.X - (pointersize.Width / 2), p.Y - (pointersize.Height / 2), pointersize.Width, pointersize.Height);
     List<UIElement> collisions = new List<UIElement>();
     IEnumerable<UIElement> hits = VisualTreeHelper.FindElementsInHostCoordinates(r, Application.Current.RootVisual);
     foreach (UIElement uiel in hits)
     {
         // COLLISIONE INTERCETTATA ... =)";
         if (typeof(Touchable).IsAssignableFrom(uiel.GetType()))
         {
             collisions.Add(uiel);
         }
     }
     return collisions;
 }
开发者ID:sugasaki,项目名称:Kinect,代码行数:16,代码来源:Transform2d.cs

示例9: GetTranslatedPoints

 /// <summary />
 internal static Point[] GetTranslatedPoints(FrameworkElement element)
 {
     Point[] pointArray = new Point[4];
     if (element != null)
     {
         GeneralTransform transform = element.TransformToVisual(null);
         pointArray[0] = transform.Transform(new Point(0.0, 0.0));
         pointArray[1] = transform.Transform(new Point(element.ActualWidth, 0.0));
         pointArray[1].X--;
         pointArray[2] = transform.Transform(new Point(0.0, element.ActualHeight));
         pointArray[2].Y--;
         pointArray[3] = transform.Transform(new Point(element.ActualWidth, element.ActualHeight));
         pointArray[3].X--;
         pointArray[3].Y--;
     }
     return pointArray;
 }
开发者ID:adamwyss,项目名称:slexplorer,代码行数:18,代码来源:PopupPlacementHelper.cs

示例10: AreBoundaryIntersecting

      public override bool AreBoundaryIntersecting(FrameworkElement cursorVisual)
      {
         try
         {
            RectangleGeometry cursorBounds =
             new RectangleGeometry(new Rect(10,10, cursorVisual.ActualWidth-20, cursorVisual.ActualHeight-20));
            RectangleGeometry targetBounds =
                new RectangleGeometry(new Rect((this.ActualWidth / 4), (2 * this.ActualHeight / 3), 1, 1));
            cursorBounds.Transform = (Transform)cursorVisual.TransformToVisual(this);

            return cursorBounds.FillContainsWithDetail(targetBounds) != IntersectionDetail.Empty;
         }
         catch (Exception e) {
            Console.WriteLine("Found exception: " + e);
            return false;
         }
      }
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:17,代码来源:PushPin.cs

示例11: BoundaryIntersectingOnSide

      public int BoundaryIntersectingOnSide(FrameworkElement cursorVisual)
      {
         RectangleGeometry cursorBounds =
             new RectangleGeometry(new Rect(0, 0, cursorVisual.ActualWidth, cursorVisual.ActualHeight));
         RectangleGeometry targetBoundsTop =
             new RectangleGeometry(new Rect(0, 0, this.ActualWidth, 1));
         RectangleGeometry targetBoundsBottom =
             new RectangleGeometry(new Rect(0, this.ActualHeight-1, this.ActualWidth, 1));
         RectangleGeometry targetBoundsLeft =
             new RectangleGeometry(new Rect(0, 5, 1, this.ActualHeight-10));
         RectangleGeometry targetBoundsRight =
             new RectangleGeometry(new Rect(this.ActualWidth - 1, 5, 1, this.ActualHeight-10));


         cursorBounds.Transform = (Transform)cursorVisual.TransformToVisual(this);


         if (cursorBounds.FillContainsWithDetail(targetBoundsLeft) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A LEFT");
            return LEFT;
         }
         else if (cursorBounds.FillContainsWithDetail(targetBoundsRight) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A RIGHT");
            return RIGHT;
         }
         else if(cursorBounds.FillContainsWithDetail(targetBoundsTop) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A TOP");
            return TOP;
         }
         else //if (cursorBounds.FillContainsWithDetail(targetBoundsBottom) != IntersectionDetail.Empty)
         {
             Console.WriteLine("FOUND A BOTTOM");
            return BOTTOM;
         }


      }
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:40,代码来源:Ruler.cs

示例12: SaveControl

        public RenderTargetBitmap SaveControl(FrameworkElement Target)
        {
            FrameworkElement Parent = Target.Parent as FrameworkElement;
            double ParentWidth, ParentHeight;

            if (Parent == null)
            {
                ParentWidth = 1000;
                ParentHeight = 1000;

                Canvas ParentCanvas = new Canvas();
                ParentCanvas.Children.Add(Target);
                Parent = ParentCanvas;
            }
            else
            {
                ParentWidth = Parent.ActualWidth;
                ParentHeight = Parent.ActualHeight;
            }

            Target.Measure(new Size(ParentWidth, ParentHeight));
            Target.Arrange(new Rect(0, 0, ParentWidth, ParentHeight));

            Target.Measure(new Size(Target.ActualWidth, Target.ActualHeight));
            Target.Arrange(new Rect(0, 0, Target.ActualWidth, Target.ActualHeight));

            Rect Rect = Target.TransformToVisual(Parent).TransformBounds(new Rect(0, 0, Target.ActualWidth, Target.ActualHeight));

            Target.Arrange(new Rect(-Rect.Left, -Rect.Top, Target.ActualWidth, Target.ActualHeight));

            RenderTargetBitmap r = new RenderTargetBitmap((int)Rect.Width, (int)Rect.Height, 96.0, 96.0, PixelFormats.Pbgra32);
            r.Render(Target);

            return r;
        }
开发者ID:habs57,项目名称:tablet-interaction,代码行数:35,代码来源:MainWindow.xaml.cs

示例13: ScrollIntoView

        /// <summary>
        /// Causes the element to scroll into view.
        /// </summary>
        /// <param name="element"> The element to scroll. </param>
        /// <exception cref="ArgumentNullException"> The <paramref name="element"/> parameter is null. </exception>
        public static void ScrollIntoView(FrameworkElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            var scrollViewer = element.GetParentByName("FieldsScrollView") as ScrollViewer;
            if (scrollViewer == null)
                return;

            try
            {
                var focusedVisualTransform = element.TransformToVisual(scrollViewer);
                var rectangle =
                    focusedVisualTransform.TransformBounds(new Rect(new Point(element.Margin.Left, element.Margin.Top), element.RenderSize));

                var newOffset = scrollViewer.VerticalOffset + rectangle.Top - 80;
                scrollViewer.ScrollToVerticalOffset(newOffset);
            }
            catch (Exception)
            {
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:27,代码来源:ScrollExtension.cs

示例14: IsOnScreen

        /// <summary>
        /// Indicates whether the specified framework element
        /// is within the bounds of the application's root visual.
        /// </summary>
        /// <param name="element">The framework element.</param>
        /// <returns>
        /// True if the rectangular bounds of the framework element
        /// are completely outside the bounds of the application's root visual.
        /// </returns>
        private static bool IsOnScreen(FrameworkElement element)
        {
            PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame;

            if (root == null)
            {
                return false;
            }

            GeneralTransform generalTransform;
            double height = root.ActualHeight;                

            try
            {
                generalTransform = element.TransformToVisual(root);
            }
            catch (ArgumentException)
            {
                return false;
            }
                
            Rect bounds = new Rect(
                generalTransform.Transform(new Point(0, 0)), 
                generalTransform.Transform(new Point(element.ActualWidth, element.ActualHeight)));

            return (bounds.Bottom > 0 && bounds.Top < height);
        }
开发者ID:JanJoris,项目名称:VikingApp,代码行数:36,代码来源:SlideInEffect.cs

示例15: ScrollIntoView

        internal void ScrollIntoView(FrameworkElement element)
        {
            // Get the ScrollHost
            ScrollViewer scrollHost = this.ScrollHost;
            if (scrollHost == null)
            {
                return;
            }

            // Get the position of the element relative to the ScrollHost
            GeneralTransform transform = null;
            try
            {
                transform = element.TransformToVisual(scrollHost);
            }
            catch (ArgumentException)
            {
                // Ignore failures when not in the visual tree
                return;
            }

            Rect itemRect = new Rect(
                transform.Transform(new Point()),
                transform.Transform(new Point(element.ActualWidth, element.ActualHeight)));

            // Scroll vertically
            double verticalOffset = scrollHost.VerticalOffset;
            double verticalDelta = 0;
            double hostBottom = scrollHost.ViewportHeight;
            double itemBottom = itemRect.Bottom;
            if (hostBottom < itemBottom)
            {
                verticalDelta = itemBottom - hostBottom;
                verticalOffset += verticalDelta;
            }

            double itemTop = itemRect.Top;
            if (itemTop - verticalDelta < 0)
            {
                verticalOffset -= verticalDelta - itemTop;
            }

            scrollHost.ScrollToVerticalOffset(verticalOffset);

            // Scroll horizontally
            double horizontalOffset = scrollHost.HorizontalOffset;
            double horizontalDelta = 0;
            double hostRight = scrollHost.ViewportWidth;
            double itemRight = itemRect.Right;
            if (hostRight < itemRight)
            {
                horizontalDelta = itemRight - hostRight;
                horizontalOffset += horizontalDelta;
            }

            double itemLeft = itemRect.Left;
            if (itemLeft - horizontalDelta < 0)
            {
                horizontalOffset -= horizontalDelta - itemLeft;
            }

            scrollHost.ScrollToHorizontalOffset(horizontalOffset);
        }
开发者ID:ruisebastiao,项目名称:Elysium-Extra,代码行数:63,代码来源:ItemsControlHelper.cs


注:本文中的System.Windows.FrameworkElement.TransformToVisual方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。