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


C# FrameworkElement.TransformToAncestor方法代码示例

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


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

示例1: CalculateCellDistance

        /// <summary>
        ///     Determines if a cell meets the criteria for being chosen. If it does, it
        ///     calculates its a "distance" that can be compared to other cells.
        /// </summary>
        /// <param name="distance">
        ///     A value that represents the distance between the mouse and the cell.
        ///     This is not necessarily an accurate pixel number in some cases.
        /// </param>
        /// <returns>
        ///     true if the cell can be a drag target. false otherwise.
        /// </returns>
        private static bool CalculateCellDistance(FrameworkElement cell, DataGridRow rowOwner, Panel itemsHost, Rect itemsHostBounds, bool isMouseInCorner, out double distance)
        {
            GeneralTransform transform = cell.TransformToAncestor(itemsHost);
            Rect cellBounds = new Rect(new Point(), cell.RenderSize);

            // Limit to only cells that are entirely visible
            if (itemsHostBounds.Contains(transform.TransformBounds(cellBounds)))
            {
                Point pt = Mouse.GetPosition(cell);
                if (isMouseInCorner)
                {
                    // When the mouse is in the corner, go by distance from center of the cell
                    Vector v = new Vector(pt.X - (cellBounds.Width * 0.5), pt.Y - (cellBounds.Height * 0.5));
                    distance = v.Length;
                    return true;
                }
                else
                {
                    Point rowPt = Mouse.GetPosition(rowOwner);
                    Rect rowBounds = new Rect(new Point(), rowOwner.RenderSize);

                    // The mouse should overlap a row or column
                    if ((pt.X >= cellBounds.Left) && (pt.X <= cellBounds.Right))
                    {
                        // The mouse is within a column
                        if ((rowPt.Y >= rowBounds.Top) && (rowPt.Y <= rowBounds.Bottom))
                        {
                            // Mouse is within the cell
                            distance = 0.0;
                        }
                        else
                        {
                            // Mouse is outside but is within a columns horizontal bounds
                            distance = Math.Abs(pt.Y - cellBounds.Top);
                        }

                        return true;
                    }
                    else if ((rowPt.Y >= rowBounds.Top) && (rowPt.Y <= rowBounds.Bottom))
                    {
                        // Mouse is outside but is within a row's vertical bounds
                        distance = Math.Abs(pt.X - cellBounds.Left);
                        return true;
                    }
                }
            }

            distance = Double.PositiveInfinity;
            return false;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:61,代码来源:DataGrid.cs

示例2: ZoomToObject

        public void ZoomToObject(FrameworkElement targetObject, bool isAnimated)
        {
            if (!isAnimated)
            {
                GeneralTransform gt = targetObject.TransformToAncestor(_rootElement);
                Point point = gt.Transform(new Point());
                Size size = new Size(targetObject.ActualWidth, targetObject.ActualHeight);

                double zoomX = _rootElement.ActualWidth / size.Width;
                double zoomY = _rootElement.ActualHeight / size.Height;
                double zoomFactor = Math.Min(zoomX, zoomY);

                Thickness margin = new Thickness();
                double diffScreenY = (_rootElement.ActualHeight - zoomFactor * size.Height);
                double diffScreenX = (_rootElement.ActualWidth - zoomFactor * size.Width);

                margin.Top = -((point.Y * zoomFactor) - ((diffScreenY / 2)));
                margin.Left = -((point.X * zoomFactor) - ((diffScreenX / 2)));

                ZoomFactor = zoomFactor;
                _rootElement.Margin = margin;
                _rootElement.UpdateLayout();
            }
            else
            {
                ZoomToObjectAnimated(targetObject);
            }
        }
开发者ID:dotCtor,项目名称:WpfControls,代码行数:28,代码来源:ZoomControl.cs

示例3: ZoomToObjectAnimated

        private void ZoomToObjectAnimated(FrameworkElement targetObject)
        {
            if (_rootElement != null)
            {
                double objectsActualCurrentZoom = 1;
                if (targetObject.LayoutTransform is ScaleTransform)
                {
                    objectsActualCurrentZoom = (targetObject.LayoutTransform as ScaleTransform).ScaleX;
                    if (targetObject is INestedZoomableControl)
                    {
                        objectsActualCurrentZoom = 1 / Math.Pow(GetScaleFactor(targetObject), (targetObject as INestedZoomableControl).NestedLevel);
                    }
                }

                GeneralTransform gt = targetObject.TransformToAncestor(_rootElement);
                Point point = gt.Transform(new Point());
                Size size = new Size(targetObject.ActualWidth * objectsActualCurrentZoom, targetObject.ActualHeight * objectsActualCurrentZoom);

                double zoomX = _rootElement.ActualWidth / size.Width;
                double zoomY = _rootElement.ActualHeight / size.Height;
                double zoomFactor = Math.Min(zoomX, zoomY);

                Thickness margin = new Thickness();
                double diffScreenY = (_rootElement.ActualHeight - zoomFactor * size.Height);
                double diffScreenX = (_rootElement.ActualWidth - zoomFactor * size.Width);

                margin.Top = -((point.Y * zoomFactor) - ((diffScreenY / 2)));
                margin.Left = -((point.X * zoomFactor) - ((diffScreenX / 2)));

                _animZoom.From = ZoomFactor;
                _animZoom.To = zoomFactor;

                _animMargin.To = margin;
                _animMargin.From = _rootElement.Margin;

                _animPositionX.To = margin.Left;
                _animPositionX.From = PositionX;

                _animPositionY.To = margin.Top;
                _animPositionY.From = PositionY;

                OnZoomStarted();
                this.BeginAnimation(ZoomFactorProperty, _animZoom);
                _rootElement.BeginAnimation(FrameworkElement.MarginProperty, _animMargin);

                if (targetObject is INotifyZoomChanged)
                {
                    (targetObject as INotifyZoomChanged).OnZoomStarted();
                    DispatcherTimer timer = new DispatcherTimer();
                    timer.Interval = AnimationDuration.TimeSpan;
                    timer.Tick += (s, e) =>
                    {
                        (targetObject as INotifyZoomChanged).OnZoomCompleted();
                        OnZoomCompleted();
                        timer.Stop();
                    };
                    timer.Start();
                }
            }
        }
开发者ID:dotCtor,项目名称:WpfControls,代码行数:60,代码来源:ZoomControl.cs

示例4: GetScaleFactor

        public double GetScaleFactor(FrameworkElement visual)
        {
            GeneralTransform gt = visual.TransformToAncestor(_rootElement);
            Point point = gt.Transform(new Point());
            Size size = new Size(visual.Width, visual.Height);

            double scaleX = _rootElement.ActualWidth / size.Width;
            double scaleY = _rootElement.ActualHeight / size.Height;
            double scaleFactor = Math.Min(scaleX, scaleY);

            return scaleFactor;
        }
开发者ID:dotCtor,项目名称:WpfControls,代码行数:12,代码来源:ZoomControl.cs


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