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


C# UIElement.TransformToVisual方法代码示例

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


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

示例1: DistanceFromTop

        public static double DistanceFromTop(this ScrollViewer scrollViewer, UIElement element)
        {
            var transform = element.TransformToVisual(scrollViewer);
            var position = transform.TransformPoint(new Point(0, 0));

            return position.Y;
        }
开发者ID:JustinXinLiu,项目名称:Parallax,代码行数:7,代码来源:Extensions.cs

示例2: SetupContinuity

        /// <summary>
        /// Set up Continuity by hooking continuing Visuals to root Frame and getting global co-ordinates so that Visual seems to remain on the same location even though pages change and local coordinate space changes as well. 
        /// </summary>
        /// <param name="containerVisual">Container Visual which contains visual that needs to continue between pages</param>
        /// <param name="hostElement">UIElement which the Visual is hosted in</param>
        /// <param name="newContainerVisual">new ContainerVisual after re-parent of sprite Visual to root.</param>
        public static void SetupContinuity(ContainerVisual containerVisual,UIElement HostElement, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == HostElement)
            {
                newContainerVisual = null;
                return;
            }
            Frame rootFrame = Window.Current.Content as Frame;
            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootFrame);
            Compositor compositor = rootVisual.Compositor;
            //remove element from current tree 
            var visualChild = containerVisual.Children.FirstOrDefault();
            containerVisual.Children.Remove(visualChild);

            //create temp container to add the visual to the root 
            ContainerVisual tempContainer = compositor.CreateContainerVisual();
            tempContainer.Children.InsertAtTop(visualChild);
            //Get location of visual as compared to root frame. 
            var coordinate = HostElement.TransformToVisual(rootFrame);
            var position = coordinate.TransformPoint(new Point(0, 0));
            //set the location of container visual to same visual location but now root as the parent.
            tempContainer.Offset = new System.Numerics.Vector3((float)position.X, (float)position.Y, 0);
            visualChild.Offset = new System.Numerics.Vector3(0, 0, 0);

            //add container with sprite to the window of app
            ElementCompositionPreview.SetElementChildVisual(rootFrame, tempContainer);
            containerVisual = null;
            newContainerVisual = tempContainer;
        }
开发者ID:HimanshPal,项目名称:composition,代码行数:35,代码来源:ContinuityHelper.cs

示例3: ScrollToElement

        public static void ScrollToElement(this ScrollViewer scrollViewer, UIElement element,
    bool isVerticalScrolling = true, bool smoothScrolling = true, float? zoomFactor = null)
        {
            var transform = element.TransformToVisual((UIElement)scrollViewer.Content);
            var position = transform.TransformPoint(new Point(0, 0));

            if (isVerticalScrolling)
            {
                scrollViewer.ChangeView(null, position.Y, zoomFactor, !smoothScrolling);
            }
            else
            {
                scrollViewer.ChangeView(position.X, null, zoomFactor, !smoothScrolling);
            }
        }
开发者ID:andrewlouie,项目名称:Appointments,代码行数:15,代码来源:Extentions.cs

示例4: ShowAt

        /// <summary>
        /// 显示菜单
        /// </summary>
        public void ShowAt(UIElement element, Point point)
        {
            if (element == null) return;

            var p = element.TransformToVisual(Window.Current.Content).TransformPoint(new Point(0, 0));
            _popup.IsLightDismissEnabled = _isLightDismissEnabled;
            _popup.HorizontalOffset = p.X + point.X;
            _popup.VerticalOffset = p.Y + point.Y;
            _popup.IsOpen = true;
        }
开发者ID:HppZ,项目名称:UniversalTest,代码行数:13,代码来源:CascadeMenu.xaml.cs

示例5: CalcOffsets

        private Point CalcOffsets(UIElement elem)
        {
            var transform = elem.TransformToVisual(this);
            Point point = transform.TransformPoint(new Point(0, 0));

            return point;
        }
开发者ID:IvayloGeorgiev,项目名称:TA-Kiwi,代码行数:7,代码来源:PubnubOperation.xaml.cs

示例6: TransformToCanvas

 Point TransformToCanvas(UIElement elem, Point pt)
 {
     GeneralTransform gt = elem.TransformToVisual(_physicsCanvas);
     return gt.TransformPoint(pt);
 }
开发者ID:badreddine-dlaila,项目名称:PhysicsHelper.UAP,代码行数:5,代码来源:PhysicsSprite.cs

示例7: PerformValueCalculation

        /// <summary>
        /// Calculates the new Value of this control using a location and relative source.
        /// The location is translated to the control, and then used to set the value.
        /// </summary>
        /// <param name="location">A point.</param>
        /// <param name="locationRelativeSource">The UIElement that the point originated from.</param>
        private void PerformValueCalculation(Point location, UIElement locationRelativeSource)
        {
            GeneralTransform gt = locationRelativeSource.TransformToVisual(this);
            location = gt.TransformPoint(location);

            int numberOfPositions = _filledItemCollection.Count;

            if (AllowHalfItemIncrement)
            {
                numberOfPositions *= 2;
            }

            double newValue;
            if (Orientation == Orientation.Horizontal)
            {
                newValue = Math.Ceiling(location.X / ActualWidth * numberOfPositions);
            }
            else
            {
                newValue = Math.Ceiling(location.Y / ActualHeight * numberOfPositions);
            }

            if (!AllowSelectingZero && newValue <= 0)
            {
                newValue = 1;
            }

            Value = newValue;
        }
开发者ID:arashadm,项目名称:WpToWinrt,代码行数:35,代码来源:Rating.cs

示例8: ShowFontPopup

        private void ShowFontPopup(UIElement targetElement)
        {
            _popUp.Child = _fontSizePopupMenu;
            var transform = targetElement.TransformToVisual(null);
            var point = transform.TransformPoint(new Point(0, 0));
            _popUp.HorizontalOffset = point.X - 40;// this.ScreenWidth - 180;
            _popUp.VerticalOffset = point.Y - 220;

            _popUp.IsOpen = true;
        }
开发者ID:anytao,项目名称:ModernReader,代码行数:10,代码来源:Viewer.xaml.cs

示例9: Start

        public void Start(UIElement newParent, CompositionImage targetImage, ScrollViewer scrollViewer, UIElement animationTarget)
        {
            Visual transitionVisual = ElementCompositionPreview.GetElementChildVisual(_parent);
            ElementCompositionPreview.SetElementChildVisual(_parent, null);


            //
            // We need to reparent the transition visual under the new parent.  This is important to ensure
            // it's propertly clipped, etc.
            //

            GeneralTransform coordinate = newParent.TransformToVisual(_parent);
            Point position = coordinate.TransformPoint(new Point(0, 0));

            Vector3 currentOffset = transitionVisual.Offset;
            currentOffset.X -= (float)position.X;
            currentOffset.Y -= (float)position.Y;
            transitionVisual.Offset = currentOffset;

            _parent = newParent;
            _targetImage = targetImage;

            // Move the transition visual to it's new parent
            ElementCompositionPreview.SetElementChildVisual(_parent, transitionVisual);

            // Hide the target Image now since the handoff visual is still transitioning
            targetImage.Opacity = 0f;

            // Load image if necessary
            _imageLoaded = targetImage.IsContentLoaded;
            if (!_imageLoaded)
            {
                targetImage.ImageOpened += CompositionImage_ImageOpened;
            }

            //
            // Create a scoped batch around the animations.  When the batch completes, we know the animations
            // have finished and we can cleanup the transition related objects.
            //

            Compositor compositor = transitionVisual.Compositor;
            _scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            //
            // Determine the offset between the parent and the target UIElement.  This will be used to calculate the
            // target position we are animating to.
            //

            coordinate = targetImage.TransformToVisual(_parent);
            position = coordinate.TransformPoint(new Point(0, 0));

            TimeSpan totalDuration = TimeSpan.FromMilliseconds(1000);
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            if (scrollViewer != null)
            {
                CompositionPropertySet scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer);

                // Include the scroller offset as that is a factor
                position.X += scrollViewer.HorizontalOffset;
                position.Y += scrollViewer.VerticalOffset;


                //
                // Since the target position is relative to the target UIElement which can move, we need to construct
                // an expression to bind the target's position to the end position of our animation.
                //

                string expression = "Vector3(scrollingProperties.Translation.X, scrollingProperties.Translation.Y, 0) + itemOffset";
                offsetAnimation.InsertExpressionKeyFrame(1f, expression);
                offsetAnimation.SetReferenceParameter("scrollingProperties", scrollProperties);
                offsetAnimation.SetVector3Parameter("itemOffset", new Vector3((float)position.X, (float)position.Y, 0));
                offsetAnimation.Duration = totalDuration;
            }
            else
            {
                offsetAnimation.InsertKeyFrame(1, new Vector3((float)position.X, (float)position.Y, 0));
                offsetAnimation.Duration = totalDuration;
            }

            // Create size animation to change size of the visual
            Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation();
            sizeAnimation.InsertKeyFrame(1f, new Vector2((float)targetImage.ActualWidth, (float)targetImage.ActualHeight));
            sizeAnimation.Duration = totalDuration;

            // Create the fade in animation for the other page content
            if (animationTarget != null)
            {
                Visual fadeVisual = ElementCompositionPreview.GetElementVisual(animationTarget);
                ScalarKeyFrameAnimation fadeIn = compositor.CreateScalarKeyFrameAnimation();
                fadeIn.InsertKeyFrame(0f, 0.0f);
                fadeIn.InsertKeyFrame(1f, 1.0f);
                fadeIn.Duration = totalDuration;
                fadeVisual.StartAnimation("Opacity", fadeIn);
            }

            //Start Animations 
            _sprite.StartAnimation("Size", sizeAnimation);
            _sprite.StartAnimation("Offset", offsetAnimation);

//.........这里部分代码省略.........
开发者ID:chenjianwp,项目名称:WindowsUIDevLabs,代码行数:101,代码来源:ConnectedTransition.cs


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