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


C# IVisual.TransformToVisual方法代码示例

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


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

示例1: BringDescendentIntoView

        /// <summary>
        /// Attempts to bring a portion of the target visual into view by scrolling the content.
        /// </summary>
        /// <param name="target">The target visual.</param>
        /// <param name="targetRect">The portion of the target visual to bring into view.</param>
        /// <returns>True if the scroll offset was changed; otherwise false.</returns>
        public bool BringDescendentIntoView(IVisual target, Rect targetRect)
        {
            if (Child != null)
            {
                var transform = target.TransformToVisual(Child);
                var rect = targetRect * transform;
                var offset = Offset;
                var result = false;

                if (rect.Bottom > offset.Y + Viewport.Height)
                {
                    offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top);
                    result = true;
                }

                if (rect.Y < offset.Y)
                {
                    offset = offset.WithY(rect.Y);
                    result = true;
                }

                if (rect.Right > offset.X + Viewport.Width)
                {
                    offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left);
                    result = true;
                }

                if (rect.X < offset.X)
                {
                    offset = offset.WithX(rect.X);
                    result = true;
                }

                if (result)
                {
                    Offset = offset;
                }

                System.Diagnostics.Debug.WriteLine($"{targetRect} {offset}");

                return result;
            }
            else
            {
                return false;
            }
        }
开发者ID:Serg2DFX,项目名称:Perspex,代码行数:53,代码来源:ScrollContentPresenter.cs

示例2: BringDescendentIntoView

        /// <summary>
        /// Attempts to bring a portion of the target visual into view by scrolling the content.
        /// </summary>
        /// <param name="target">The target visual.</param>
        /// <param name="targetRect">The portion of the target visual to bring into view.</param>
        /// <returns>True if the scroll offset was changed; otherwise false.</returns>
        public bool BringDescendentIntoView(IVisual target, Rect targetRect)
        {
            if (Child == null)
            {
                return false;
            }

            var transform = target.TransformToVisual(Child);

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

            var rect = targetRect * transform.Value;
            var offset = Offset;
            var result = false;

            if (rect.Bottom > offset.Y + Viewport.Height)
            {
                offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top);
                result = true;
            }

            if (rect.Y < offset.Y)
            {
                offset = offset.WithY(rect.Y);
                result = true;
            }

            if (rect.Right > offset.X + Viewport.Width)
            {
                offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left);
                result = true;
            }

            if (rect.X < offset.X)
            {
                offset = offset.WithX(rect.X);
                result = true;
            }

            if (result)
            {
                Offset = offset;
            }

            return result;
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:55,代码来源:ScrollContentPresenter.cs

示例3: BringDescendentIntoView

        /// <summary>
        /// Attempts to bring a portion of the target visual into view by scrolling the content.
        /// </summary>
        /// <param name="target">The target visual.</param>
        /// <param name="targetRect">The portion of the target visual to bring into view.</param>
        /// <returns>True if the scroll offset was changed; otherwise false.</returns>
        public bool BringDescendentIntoView(IVisual target, Rect targetRect)
        {
            if (Child == null)
            {
                return false;
            }

            var scrollable = Child as ILogicalScrollable;
            var control = target as IControl;

            if (scrollable?.IsLogicalScrollEnabled == true && control != null)
            {
                return scrollable.BringIntoView(control, targetRect);
            }

            var transform = target.TransformToVisual(Child);

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

            var rect = targetRect * transform.Value;
            var offset = Offset;
            var result = false;

            if (rect.Bottom > offset.Y + Viewport.Height)
            {
                offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top);
                result = true;
            }

            if (rect.Y < offset.Y)
            {
                offset = offset.WithY(rect.Y);
                result = true;
            }

            if (rect.Right > offset.X + Viewport.Width)
            {
                offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left);
                result = true;
            }

            if (rect.X < offset.X)
            {
                offset = offset.WithX(rect.X);
                result = true;
            }

            if (result)
            {
                Offset = offset;
            }

            return result;
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:63,代码来源:ScrollContentPresenter.cs


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