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


C# FrameworkElement.TransformToVisual方法代码示例

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


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

示例1: IsItemVisible

        public static bool IsItemVisible(this FrameworkElement container, FrameworkElement element)
        {
            var elementBounds = element.TransformToVisual(container).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight));
            var containerBounds = new Rect(0, 0, container.ActualWidth, container.ActualHeight);

            return (elementBounds.Top < containerBounds.Bottom && elementBounds.Bottom > containerBounds.Top);
        }
开发者ID:JustinXinLiu,项目名称:Parallax,代码行数:7,代码来源:Extensions.cs

示例2: GetPosition

        private Point GetPosition(FrameworkElement sender)
        {
            GeneralTransform transform = sender.TransformToVisual(null);
            Point location = transform.TransformPoint(new Point());
            location.Y = location.Y + sender.ActualHeight;

            return location;
        }
开发者ID:Jxperez,项目名称:31DaysOfWindows8,代码行数:8,代码来源:MainPage.xaml.cs

示例3: GetElementBounds

 private Rect GetElementBounds(FrameworkElement element, FrameworkElement parent)
 {
     if (element == null || parent == null)
     {
         return Rect.Empty;
     }
     if (element.Visibility != Visibility.Visible)
     {
         return Rect.Empty;
     }
     return element.TransformToVisual(parent).TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight));
 }
开发者ID:bajirav,项目名称:TFAmvvm,代码行数:12,代码来源:MainPage.xaml.cs

示例4: GetCenterToCenterDelta

 /// <summary>
 /// Computes the delta between the centre of an element and its 
 /// container.
 /// </summary>
 /// <param name="element">The element to compare.</param>
 /// <param name="container">The element to compare against.</param>
 /// <returns>A point that represents the delta between the two centers.</returns>
 private static Point GetCenterToCenterDelta(FrameworkElement element, FrameworkElement container)
 {
     Point elementCenter = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
     Point containerCenter = new Point(container.ActualWidth / 2, container.ActualHeight / 2);
     Point transformedElementCenter = element.TransformToVisual(container).TransformPoint(elementCenter);
     return new Point(containerCenter.X - transformedElementCenter.X, containerCenter.Y - transformedElementCenter.Y);
 }
开发者ID:liquidboy,项目名称:X,代码行数:14,代码来源:TiltEffect.cs

示例5: GetElementRect

 private Rect GetElementRect(FrameworkElement frameworkElement)
 {
     Windows.UI.Xaml.Media.GeneralTransform transform = frameworkElement.TransformToVisual(null);
     Point point = transform.TransformPoint(new Point());
     return new Rect(point, new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight));
 }
开发者ID:yqhou,项目名称:ICSReader,代码行数:6,代码来源:MainPage.xaml.cs

示例6: ScrollIntoView

        internal void ScrollIntoView(FrameworkElement element)
        {
            var scrollHost = ScrollHost;
            if (scrollHost == null)
            {
                return;
            }
            GeneralTransform transform;
            try
            {
                transform = element.TransformToVisual(scrollHost);
            }
            catch (ArgumentException)
            {
                return;
            }
            var itemRect = new Rect(transform.TransformPoint(new Point()),
                transform.TransformPoint(new Point(element.ActualWidth, element.ActualHeight)));
            var verticalOffset = scrollHost.VerticalOffset;
            double verticalDelta = 0;
            var hostBottom = scrollHost.ViewportHeight;
            var itemBottom = itemRect.Bottom;
            if (hostBottom < itemBottom)
            {
                verticalDelta = itemBottom - hostBottom;
                verticalOffset += verticalDelta;
            }
            var itemTop = itemRect.Top;
            if (itemTop - verticalDelta < 0)
            {
                verticalOffset -= verticalDelta - itemTop;
            }

            var horizontalOffset = scrollHost.HorizontalOffset;
            double horizontalDelta = 0;
            var hostRight = scrollHost.ViewportWidth;
            var itemRight = itemRect.Right;
            if (hostRight < itemRight)
            {
                horizontalDelta = itemRight - hostRight;
                horizontalOffset += horizontalDelta;
            }
            var itemLeft = itemRect.Left;
            if (itemLeft - horizontalDelta < 0)
            {
                horizontalOffset -= horizontalDelta - itemLeft;
            }
            scrollHost.ChangeView(horizontalOffset, verticalOffset, null);
        }
开发者ID:JanJoris,项目名称:Expander,代码行数:49,代码来源:ItemsControlHelper.cs

示例7: InitiateContinuity

        /// <summary>
        /// Start animations and re-parent to destination UI Elmenent to finish the operations
        /// </summary>
        /// <param name="destinationElement">Destination UIElement where Visual should show up after page has loaded</param>
        /// <param name="containerVisual">ContainerVisual that contains Visual which needs to show in UIElement</param>
        /// <param name="newContainerVisual">ContainerVisual after visual is parented to UIElement</param>
        public static void InitiateContinuity(FrameworkElement destinationElement, ContainerVisual containerVisual, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == destinationElement)
            {
                newContainerVisual = null;
                return;
            }
            //Get the frame of Window
            Frame rootFrame = Window.Current.Content as Frame;
            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootFrame);
            Compositor compositor = rootVisual.Compositor;
            //Create Temporary Container. this will be added to final UIElement 
            ContainerVisual _TempContainer = compositor.CreateContainerVisual();
            // Get Sprite Visual from incoming container
            var spriteHeroImage = containerVisual.Children.FirstOrDefault();

            //Create animation scoped batch to track animation completion and to complete re-parenting
            CompositionScopedBatch scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            //Get coordinates of UIElement in reference to root so that it can be used for animations final value
            var coordinate = destinationElement.TransformToVisual(rootFrame);
            var position = coordinate.TransformPoint(new Point(0, 0));
            
            //Create offset animation to make visual move on screen
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            offsetAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3((float)position.X, (float)position.Y, 0));
            offsetAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Create size animation to change size of the visuals 
            Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation();
            sizeAnimation.InsertKeyFrame(1f, new System.Numerics.Vector2((float)destinationElement.ActualWidth, (float)destinationElement.ActualHeight));
            sizeAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Start Animations 
            spriteHeroImage.StartAnimation("size", sizeAnimation);
            containerVisual.StartAnimation("offset", offsetAnimation);
            //Scoped batch completed event. 
            scopeBatch.Completed += (o, e) =>
            {
                //Re-parent SpriteVisual to temp container and add temp container to UIElement as animations are finished.
                spriteHeroImage.Offset = new System.Numerics.Vector3(0, 0, 0);
                containerVisual.Children.Remove(spriteHeroImage);
                _TempContainer.Children.InsertAtTop(spriteHeroImage);
                ElementCompositionPreview.SetElementChildVisual(destinationElement, _TempContainer);
                containerVisual = null;

            };
            newContainerVisual = _TempContainer;

            scopeBatch.End();
        }
开发者ID:HimanshPal,项目名称:composition,代码行数:57,代码来源:ContinuityHelper.cs

示例8: GetElementRect

 private Windows.Foundation.Rect GetElementRect(FrameworkElement element)
 {
     Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);
     Windows.Foundation.Point point = buttonTransform.TransformPoint(new Windows.Foundation.Point());
     return new Windows.Foundation.Rect(point, new Windows.Foundation.Size(element.ActualWidth, element.ActualHeight));
 }
开发者ID:youssefadel94,项目名称:tile-reminder,代码行数:6,代码来源:MainPage.xaml.cs

示例9: GetPosition

 private Point GetPosition(FrameworkElement element)
 {
     return element.TransformToVisual(this.listBox).TransformPoint(new Point(0, 0));
 }
开发者ID:kantlove,项目名称:DynamicWrapPanel,代码行数:4,代码来源:Wrapper.xaml.cs

示例10: GetTransformedPoints

        private Point[] GetTransformedPoints(FrameworkElement element, bool isRTL, FrameworkElement relativeTo)
        {
            Point[] pointArray = new Point[4];
            if ((element != null) && (relativeTo != null))
            {
                GeneralTransform gt = relativeTo.TransformToVisual(_rootVisual);
                pointArray[0] = gt.TransformPoint(new Point(0.0, 0.0));
                pointArray[1] = gt.TransformPoint(new Point(element.ActualWidth, 0.0));
                pointArray[2] = gt.TransformPoint(new Point(0.0, element.ActualHeight));
                pointArray[3] = gt.TransformPoint(new Point(element.ActualWidth, element.ActualHeight));

                FrameworkElement _el = _rootVisual as FrameworkElement;
                bool flag = (_el != null) ? (_el.FlowDirection == FlowDirection.RightToLeft) : false;
                if (isRTL != flag)
                {
                    // TODO: Handle RTL - GetTransformedPoints
                    //for (int i = 0; i < pointArray.Length; i++)
                    //{
                    //    pointArray[i].X = _windowBounds.Width - pointArray[i].X;
                    //}
                }
            }
            return pointArray;
        }
开发者ID:larsduewel,项目名称:callisto,代码行数:24,代码来源:Flyout.cs

示例11: ScrollIntoView

        internal void ScrollIntoView(FrameworkElement element)
        {
            // Get the ScrollHost
            ScrollViewer scrollHost = 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.TransformPoint(new Point()),
                transform.TransformPoint(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;
            }

#pragma warning disable 4014
            scrollHost.ScrollToVerticalOffsetWithAnimationAsync(verticalOffset);
#pragma warning restore 4014

            // 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;
            }

#pragma warning disable 4014
            scrollHost.ScrollToHorizontalOffsetWithAnimationAsync(horizontalOffset);
#pragma warning restore 4014
        }
开发者ID:karpinsn,项目名称:AntStrength,代码行数:73,代码来源:ItemsControlHelper.cs

示例12: GetElementRect

 public static Rect GetElementRect(FrameworkElement element)
 {
     GeneralTransform buttonTransform = element.TransformToVisual(null);
     Windows.Foundation.Point point = buttonTransform.TransformPoint(new Windows.Foundation.Point());
     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }
开发者ID:rolandsmeenk,项目名称:ModernApps,代码行数:6,代码来源:TileService.cs

示例13: GetElementRect

        //get the bounding rect of an element relative to 0,0
        private static Rect GetElementRect(FrameworkElement element)
        {
            //get the element point to open the window at the correct point
            GeneralTransform transform = element.TransformToVisual(null);
            Point point = transform.TransformPoint(new Point());

            return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
        }
开发者ID:CHS982,项目名称:Coding4Fun,代码行数:9,代码来源:MainPage.xaml.cs

示例14: GetElementRect

 public static Rect GetElementRect(FrameworkElement element)
 {
     Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);
     Point point = buttonTransform.TransformPoint(new Point());
     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }
开发者ID:mbin,项目名称:Win81App,代码行数:6,代码来源:Constants.cs

示例15: IsUserVisible

 /// <summary>
 /// Determine whether an element is visible, assuming the container is visible.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="container"></param>
 /// <returns></returns>
 private Boolean IsUserVisible(FrameworkElement element, FrameworkElement container)
 {
     if (element == null)
         return false;
     Rect elementBounds = element.TransformToVisual(container)
         .TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight));
     Rect containerBounds = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
     return (elementBounds.Top < containerBounds.Bottom && elementBounds.Bottom > containerBounds.Top)
         && (elementBounds.Left < containerBounds.Right && elementBounds.Right > containerBounds.Left);
 }
开发者ID:qiuosier,项目名称:Libra,代码行数:16,代码来源:ViewerPage.xaml.cs


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