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


C# FrameworkElement.TransformToAncestor方法代码示例

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


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

示例1: ComputeIntersectionPoint

        public static Point ComputeIntersectionPoint(FrameworkElement thisV, FrameworkElement toV)
        {
            PathGeometry fromGeometryFlat;
            //using the cached geometry or building one up
            fromGeometryFlat = BuildVertexGeometry(thisV);
            if (toV != null)
            {
                //transforming the argument vertex's center to the coordinate space of this vertex
                Panel panel = (Panel)VisualTreeHelper.GetParent(thisV);
                Transform transformToPanel = (Transform)toV.TransformToAncestor(panel);
                Transform transformToFromV = (Transform)panel.TransformToDescendant(thisV);
                Point transformedToVCenter = new Point(toV.RenderSize.Width / 2, toV.RenderSize.Height / 2);
                if (transformToPanel != null)
                    transformedToVCenter = transformToPanel.Transform(transformedToVCenter);
                if (transformToFromV != null)
                    transformedToVCenter = transformToFromV.Transform(transformedToVCenter);

                Point thisCenter = new Point(thisV.RenderSize.Width / 2, thisV.RenderSize.Height / 2);
                Vector centerVector = thisCenter - transformedToVCenter;
                //getting intersection point in the coordinate space of this vertex
                Point p1 = FindOppositePoint(fromGeometryFlat, transformedToVCenter, centerVector, null);
                //transforming back to the panel coordinate space
                if (transformToFromV != null)
                    p1 = transformToFromV.Inverse.Transform(p1);
                return p1;
            }
            return new Point(thisV.RenderSize.Width/2, thisV.RenderSize.Height/2);
        }
开发者ID:CarlosVV,项目名称:mediavf,代码行数:28,代码来源:GeometryOperation.cs

示例2: ExcludeElementFromAeroGlass

        /// <summary>
        /// Excludes a UI element from the AeroGlass frame.
        /// </summary>
        /// <param name="element">The element to exclude.</param>
        /// <remarks>Many non-WPF rendered controls (i.e., the ExplorerBrowser control) will not 
        /// render properly on top of an AeroGlass frame. </remarks>
        public void ExcludeElementFromAeroGlass(FrameworkElement element)
        {
            if (AeroGlassCompositionEnabled && element != null)
            {
                // calculate total size of window nonclient area
                HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                NativeRect windowRect;
                NativeRect clientRect;
                DesktopWindowManagerNativeMethods.GetWindowRect(hwndSource.Handle, out windowRect);
                DesktopWindowManagerNativeMethods.GetClientRect(hwndSource.Handle, out clientRect);
                Size nonClientSize = new Size(
                        (double)(windowRect.Right - windowRect.Left) - (double)(clientRect.Right - clientRect.Left),
                        (double)(windowRect.Bottom - windowRect.Top) - (double)(clientRect.Bottom - clientRect.Top));

                // calculate size of element relative to nonclient area
                GeneralTransform transform = element.TransformToAncestor(this);
                Point topLeftFrame = transform.Transform(new Point(0, 0));
                Point bottomRightFrame = transform.Transform(new Point(
                            element.ActualWidth + nonClientSize.Width,
                            element.ActualHeight + nonClientSize.Height));

                // Create a margin structure
                Margins margins = new Margins();
                margins.LeftWidth = (int)topLeftFrame.X;
                margins.RightWidth = (int)(this.ActualWidth - bottomRightFrame.X);
                margins.TopHeight = (int)(topLeftFrame.Y);
                margins.BottomHeight = (int)(this.ActualHeight - bottomRightFrame.Y);

                // Extend the Frame into client area
                DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea(windowHandle, ref margins);
            }
        }
开发者ID:snowmizuh,项目名称:Shellscape.Common,代码行数:38,代码来源:GlassWindow.cs

示例3: GetVisibleWidth

        public static double GetVisibleWidth(FrameworkElement element, UIElement parent)
        {
            if (element == null) throw new ArgumentNullException(nameof(element));
            if (parent == null) throw new ArgumentNullException(nameof(parent));

            var location = element.TransformToAncestor(parent).Transform(new Point(0, 0));

            int width = (int) Math.Floor(element.ActualWidth);
            var hitTest = parent.InputHitTest(new Point(location.X + width, location.Y));

            if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
            {
                return width;
            }

            //BinarySearch here
            int end = (int) Math.Floor(element.ActualWidth);
            int start = 0;

            while (start < end)
            {
                width = (end + start)/2;
                hitTest = parent.InputHitTest(new Point(location.X + width, location.Y));

                if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
                {
                    //Speed tweak
                    hitTest = parent.InputHitTest(new Point(location.X + width + 1, location.Y));

                    if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
                    {
                        start = width;
                    }
                    else
                    {
                        return width;
                    }
                }
                else
                {
                    end = width;
                }
            }


            //for (int width = (int) Math.Floor(element.ActualWidth); width >= 0; width--)
            //{
            //    var hitTest = parent.InputHitTest(new Point(location.X + width, location.Y));
            //
            //    if (hitTest == null) continue;
            //    
            //    if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
            //    {
            //        return width;
            //    }
            //}

            return element.ActualWidth;
        }
开发者ID:flying19880517,项目名称:MaterialDesignInXamlToolkit,代码行数:59,代码来源:TreeHelper.cs

示例4: ClientToScreen

        public static IntPoint ClientToScreen(FrameworkElement element, Point point)
        {
            PresentationSource source = PresentationSource.FromVisual(element);
            point = element.TransformToAncestor(source.RootVisual).Transform(point);

            Point offset = source.CompositionTarget.TransformToDevice.Transform(new Point(point.X, point.Y));

            Win32Point winPt = new Win32Point((int)offset.X, (int)offset.Y);
            NativeMethods.ClientToScreen(((HwndSource)source).Handle, ref winPt);

            return new IntPoint(winPt.x, winPt.y);
        }
开发者ID:RSchwoerer,项目名称:rooler,代码行数:12,代码来源:NativeMethods.cs

示例5: GetVisualTopLeftRelativeParent

 public static Point GetVisualTopLeftRelativeParent(FrameworkElement reference, Window parent)
 {
     return reference.TransformToAncestor(parent).Transform(new Point(0.0, 0.0));
 }
开发者ID:QuocHuy7a10,项目名称:Arianrhod,代码行数:4,代码来源:VisualTree.cs

示例6: IsElementVisible

        private bool IsElementVisible(FrameworkElement element, FrameworkElement container)
        {
            if (!element.IsVisible)
                return false;

            // "element" here represents the "Border" object which contains TextBlock/Image of 
            // a class button. "container" here is the "ScrollLibraryViewer" on the library. 
            // The bounds of this class button is transformed to the rectangle it occupies in 
            // the "ScrollLibraryViewer" before being compared to the the region of container 
            // to determine if it lies outside of the container.
            // 
            var elementRect = new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight);
            var containerRect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
            elementRect = element.TransformToAncestor(container).TransformBounds(elementRect);
            return containerRect.IntersectsWith(elementRect);
        }
开发者ID:RevitLution,项目名称:Dynamo,代码行数:16,代码来源:LibraryView.xaml.cs

示例7: ApplySlideOutToTop

        private void ApplySlideOutToTop(FrameworkElement fe, Duration duration, Duration delay)
        {
            GeneralTransform transform = fe.TransformToAncestor(this);
             Point slidepoint = transform.Transform(new Point(0, fe.ActualHeight));

             if (delay.TimeSpan == TimeSpan.Zero)
             {
            DoubleAnimation da = new DoubleAnimation(0, -slidepoint.Y, duration);
            da.AccelerationRatio = da.DecelerationRatio = 0.2;
            fe.RenderTransformOrigin = new Point(0, 0);
            fe.RenderTransform = new TranslateTransform(0, 0);
            fe.RenderTransform.BeginAnimation(TranslateTransform.YProperty, da);
             }
             else
             {
            DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
            da.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(TimeSpan.Zero)));
            da.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(delay.TimeSpan)));
            da.KeyFrames.Add(new LinearDoubleKeyFrame(-slidepoint.Y, KeyTime.FromTimeSpan(delay.TimeSpan + duration.TimeSpan)));
            da.Duration = delay + duration;
            da.AccelerationRatio = da.DecelerationRatio = 0.2;
            fe.RenderTransformOrigin = new Point(0, 0);
            fe.RenderTransform = new TranslateTransform(0, 0);
            fe.RenderTransform.BeginAnimation(TranslateTransform.YProperty, da);
             }
        }
开发者ID:rmarinho,项目名称:babysmash,代码行数:26,代码来源:AnimationBehaviors.cs

示例8: FindPoint

 protected Point FindPoint(FrameworkElement border, Point point)
 {
     var transform = border.TransformToAncestor((Visual) AdornedItemsControl);
     return transform.Transform(point);
 }
开发者ID:ArildF,项目名称:PTB,代码行数:5,代码来源:TaskboardAdornerBase.cs

示例9: ExcludeElementFromAeroGlass

        /// <summary>Excludes a UI element from the Aero Glass frame.</summary>
        /// <param name="element">The element to exclude.</param>
        /// <param name="window">The window the element resides in.</param>
        /// <remarks>
        ///   cMany non-WPF rendered controls (i.e., the ExplorerBrowser control) will not render properly on top of an
        ///   Aero Glass frame.
        /// </remarks>
        public static void ExcludeElementFromAeroGlass(FrameworkElement element, Window window)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            IntPtr handle = new WindowInteropHelper(window).Handle;

            if (!IsGlassEnabled)
            {
                return;
            }

            // calculate total size of window non-client area
            var handleSource = PresentationSource.FromVisual(window) as HwndSource;
            var windowRect = new Rect();
            var clientRect = new Rect();
            if (handleSource != null)
            {
                NativeMethods.GetWindowRect(handleSource.Handle, ref windowRect);
                NativeMethods.GetClientRect(handleSource.Handle, ref clientRect);
            }

            var nonClientSize =
                new Size(
                    (windowRect.Right - windowRect.Left) - (double)(clientRect.Right - clientRect.Left),
                    (windowRect.Bottom - windowRect.Top) - (double)(clientRect.Bottom - clientRect.Top));

            // calculate size of element relative to non-client area
            GeneralTransform transform = element.TransformToAncestor(window);
            Point topLeftFrame = transform.Transform(new Point(0, 0));
            Point bottomRightFrame =
                transform.Transform(
                    new Point(element.ActualWidth + nonClientSize.Width, element.ActualHeight + nonClientSize.Height));

            // Create a margin structure
            var margins = new Margins(
                (int)topLeftFrame.X,
                (int)topLeftFrame.Y,
                (int)(window.ActualWidth - bottomRightFrame.X),
                (int)(window.ActualHeight - bottomRightFrame.Y));

            // Extend the Frame into client area
            if (NativeMethods.DwmExtendFrameIntoClientArea(handle, ref margins) != 0)
            {
                // throw new InvalidOperationException();
            }
        }
开发者ID:robertbaker,项目名称:SevenUpdate,代码行数:61,代码来源:AeroGlass.cs

示例10: 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:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:61,代码来源:DataGrid.cs

示例11: AdjustOffsetToAlignWithEdge

        private void AdjustOffsetToAlignWithEdge(FrameworkElement element, FocusNavigationDirection direction)
        {
            Debug.Assert(ScrollHost != null, "This operation to adjust the offset along an edge is only possible when there is a ScrollHost available");

            if (VirtualizingPanel.GetScrollUnit(this) != ScrollUnit.Item)
            {
                ScrollViewer scrollHost = ScrollHost;
                FrameworkElement viewportElement = GetViewportElement();
                element = TryGetTreeViewItemHeader(element) as FrameworkElement;
                Rect elementBounds = new Rect(new Point(), element.RenderSize);
                elementBounds = element.TransformToAncestor(viewportElement).TransformBounds(elementBounds);
                bool isHorizontal = (ItemsHost.HasLogicalOrientation && ItemsHost.LogicalOrientation == Orientation.Horizontal);

                if (direction == FocusNavigationDirection.Down)
                {
                    // Align with the bottom edge of viewport
                    if (isHorizontal)
                    {
                        scrollHost.ScrollToHorizontalOffset(scrollHost.HorizontalOffset - scrollHost.ViewportWidth + elementBounds.Right);
                    }
                    else
                    {
                        scrollHost.ScrollToVerticalOffset(scrollHost.VerticalOffset - scrollHost.ViewportHeight + elementBounds.Bottom);
                    }
                }
                else if (direction == FocusNavigationDirection.Up)
                {
                    // Align with the top edge of viewport
                    if (isHorizontal)
                    {
                        scrollHost.ScrollToHorizontalOffset(scrollHost.HorizontalOffset + elementBounds.Left);
                    }
                    else
                    {
                        scrollHost.ScrollToVerticalOffset(scrollHost.VerticalOffset + elementBounds.Top);
                    }
                }
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:39,代码来源:ItemsControl.cs

示例12: CalculateViewRenderTransformOrigin

        private Point CalculateViewRenderTransformOrigin(Panel panel, FrameworkElement element) {
            if (panel == null || element == null
                || Math.Abs(panel.ActualWidth - 0) < double.Epsilon
                || Math.Abs(panel.ActualHeight - 0) < double.Epsilon)
                return ViewRenderTransformOriginDefaultValue;

            // The Old Solution:
            //var panelPoint = panel.PointToScreen(ZeroPoint);
            //var elementPoint = element.PointToScreen(ZeroPoint);
            //var centerX = (elementPoint.X - panelPoint.X) + (element.ActualWidth / 2);
            //var centerY = (elementPoint.Y - panelPoint.Y) + (element.ActualHeight / 2);

            // The New One:
            var relativeElementPoint = element.TransformToAncestor(panel).Transform(new Point(0, 0));
            var centerX = (relativeElementPoint.X) + (element.ActualWidth / 2);
            var centerY = (relativeElementPoint.Y) + (element.ActualHeight / 2);

            var percentX = centerX * 100 / panel.ActualWidth;
            var percentY = centerY * 100 / panel.ActualHeight;
            var originX = percentX / 100;
            var originY = percentY / 100;

            return new Point(originX, originY);
        }
开发者ID:kavand,项目名称:Kavand.Windows.Controls,代码行数:24,代码来源:CalendarViewPresenter.cs

示例13: ElementPastBoundary

        private bool ElementPastBoundary(FrameworkElement fe, out Vector pastEdgeVector)
        {
            bool pastEdge = false;

            pastEdgeVector = new Vector();

            FrameworkElement feParent = fe.Parent as FrameworkElement;
            if (feParent != null)
            {
                Rect feRect = fe.TransformToAncestor(feParent).TransformBounds(
                    new Rect(0.0, 0.0, fe.ActualWidth, fe.ActualHeight));

                if (feRect.Left > feParent.ActualWidth - 20)
                    pastEdgeVector.X = feRect.Left - (feParent.ActualWidth - 20);

                if (feRect.Right < 20)
                    pastEdgeVector.X = feRect.Right - 20;

                if (feRect.Top > feParent.ActualHeight - 20)
                    pastEdgeVector.Y = feRect.Top - (feParent.ActualHeight - 20);

                if (feRect.Bottom < 20)
                    pastEdgeVector.Y = feRect.Bottom - 20;

                if ((pastEdgeVector.X != 0) || (pastEdgeVector.Y != 0))
                    pastEdge = true;
            }

            return pastEdge;
        }
开发者ID:aert,项目名称:aert-csharp-extensions,代码行数:30,代码来源:TouchImageHelper.cs

示例14: ScrollIntoView

 /// <summary>
 /// Scroll the given framework element into view using a smooth animation.
 /// </summary>
 /// <param name="e"></param>
 public Rect ScrollIntoView(FrameworkElement e)
 {
     StopAnimations();
     Rect rect = new Rect(0, 0, e.ActualWidth, e.ActualHeight);
     // Get zoomed & translated coordinates of this object by transforming to the container coordinates.
     rect = e.TransformToAncestor(_container).TransformBounds(rect);
     rect.Inflate(margin, margin);
     ScrollIntoView(rect, new Duration(TimeSpan.FromMilliseconds(_defaultZoomTime)), true);
     return rect;
 }
开发者ID:WonderPanda,项目名称:Besieged,代码行数:14,代码来源:MapZoom.cs

示例15: GetBoundingBox

 private Rect GetBoundingBox(FrameworkElement element, Window containerWindow)
 {
     GeneralTransform transform = element.TransformToAncestor(containerWindow);
     Point topLeft = transform.Transform(new Point(0, 0));
     Point bottomRight = transform.Transform(new Point(element.ActualWidth, element.ActualHeight));
     return new Rect(topLeft, bottomRight);
 }
开发者ID:ORRNY66,项目名称:GS,代码行数:7,代码来源:CaptureDirectShowV1.cs


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