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


C# UIElement.TransformToAncestor方法代码示例

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


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

示例1: PointToWindow

 public static Point PointToWindow(UIElement element, Point pointOnElement)
 {
     Window wnd = Window.GetWindow(element);
     if (wnd == null)
     {
     throw new InvalidOperationException("target element is not yet connected to the Window drawing surface");
     }
     return element.TransformToAncestor(wnd).Transform(pointOnElement);
 }
开发者ID:sgarces,项目名称:BankPrototype,代码行数:9,代码来源:Utilities.cs

示例2: GetLocalRect

        // Get bounding rectangle, in coords relative to root (not screen)
        internal static Rect GetLocalRect( UIElement element )
        {
            // Get top-most visual.
            Visual parent = GetRoot( element );

            // Get the points for the rectangle and transform them.
            double height = element.RenderSize.Height;
            double width = element.RenderSize.Width;
            Rect rect = new Rect(0, 0, width, height);
            
            GeneralTransform g = element.TransformToAncestor(parent);
            return g.TransformBounds(rect);            
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:14,代码来源:ElementUtil.cs

示例3: CalculateVisibleBoundingRect

        ///<summary>
        /// This eliminates the part of bounding rectangle if it is at all being overlapped/clipped by any of the visual ancestor up in the parent chain
        ///</summary>
        internal static Rect CalculateVisibleBoundingRect(UIElement owner)
        {
            Rect boundingRect = new Rect(owner.RenderSize);
            
            // Compute visible portion of the rectangle.

            DependencyObject parent = VisualTreeHelper.GetParent(owner);
            
            while (parent != null && 
                   !DoubleUtil.AreClose(boundingRect, Rect.Empty) && 
                   !DoubleUtil.AreClose(boundingRect.Height, 0) && 
                   !DoubleUtil.AreClose(boundingRect.Width, 0))
            {
                Visual visualParent = parent as Visual;
                if (visualParent != null)
                {
                    Geometry clipGeometry = VisualTreeHelper.GetClip(visualParent);
                    if (clipGeometry != null)
                    {
                        GeneralTransform transform = owner.TransformToAncestor(visualParent).Inverse;
                        // Safer version of transform to descendent (doing the inverse ourself and saves us changing the co-ordinate space of the owner's bounding rectangle), 
                        // we want the rect inside of our space. (Which is always rectangular and much nicer to work with)
                        if (transform != null)
                        {
                            Rect clipBounds = clipGeometry.Bounds;
                            clipBounds = transform.TransformBounds(clipBounds);
                            boundingRect.Intersect(clipBounds);
                        }
                        else
                        {
                            // No visibility if non-invertable transform exists.
                            boundingRect = Rect.Empty;
                        }
                    }
                }

                parent = VisualTreeHelper.GetParent(parent);
            }

            return boundingRect;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:44,代码来源:UIElementAutomationPeer.cs

示例4: ClientToScreen

        internal static Point ClientToScreen(UIElement relativeTo, Point point)
        {
            GeneralTransform transform;
            PresentationSource source = PresentationSource.CriticalFromVisual(relativeTo);

            if (source == null)
            {
                return new Point(double.NaN, double.NaN);
            }
            transform = relativeTo.TransformToAncestor(source.RootVisual);
            Point ptRoot;
            transform.TryTransform(point, out ptRoot);
            Point ptClient = PointUtil.RootToClient(ptRoot, source);
            Point ptScreen = PointUtil.ClientToScreen(ptClient, source);

            return ptScreen;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:17,代码来源:SafeSecurityHelper.cs

示例5: GetCurrentLayoutInfo

        protected override Transform GetCurrentLayoutInfo(UIElement element, out Point arrangePosition)
        {
            var group = (TransformGroup) element.RenderTransform;

            Point currentPos = element.TransformToAncestor(this).Transform(new Point());
            arrangePosition = new Point(0, 0);
            if (@group.Inverse != null) arrangePosition = @group.Inverse.Transform(currentPos);

            return group.Children[1];
        }
开发者ID:0M3G4,项目名称:OCTGN,代码行数:10,代码来源:WrapPanel.cs

示例6: GetControlRectInWindowSpace

 public static Rect GetControlRectInWindowSpace(UIElement element)
 {
     Visual ancestor = (Visual)null;
     PresentationSource presentationSource = PresentationSource.FromVisual((Visual)element);
     if (presentationSource != null)
         ancestor = presentationSource.RootVisual;
     if (ancestor != null)
         return element.TransformToAncestor(ancestor).TransformBounds(new Rect(element.RenderSize));
     return Rect.Empty;
 }
开发者ID:sulerzh,项目名称:chart,代码行数:10,代码来源:LayoutUtilities.cs

示例7: GetControlScaleInWindowSpace

 public static Point GetControlScaleInWindowSpace(UIElement element)
 {
     Visual ancestor = (Visual)null;
     PresentationSource presentationSource = PresentationSource.FromVisual((Visual)element);
     if (presentationSource != null)
         ancestor = presentationSource.RootVisual;
     if (ancestor == null)
         return new Point(1.0, 1.0);
     Transform transform = (Transform)element.TransformToAncestor(ancestor);
     return new Point(transform.Value.M11, transform.Value.M22);
 }
开发者ID:sulerzh,项目名称:chart,代码行数:11,代码来源:LayoutUtilities.cs

示例8: TransformToScreenRoot

		internal static GeneralTransform TransformToScreenRoot(UIElement target)
		{
			if (BrowserInteropHelper.IsBrowserHosted)
			{
				return target.TransformToAncestor(GetRootVisual(target));
			}
			else
			{
				var rootWindow = Window.GetWindow(target);
				if (rootWindow != null)
				{
					var transform = target.TransformToAncestor(rootWindow) as Transform;
					var windowPosition = DpiHelper.DevicePixelsToLogical(rootWindow.PointToScreen(new Point(0, 0)));

					return new TransformGroup
					{
						Children =
						{
							transform,
							new TranslateTransform 
							{ 
								X = windowPosition.X,
								Y = windowPosition.Y,
							}
						}
					};
				}
				else
				{
					// This code is ONLY for WindowsForms application that hosts the WPF.
					var element = GetParents(target).OfType<Visual>().Where(o => o.ReadLocalValue(WindowInteropabilityHelper.WindowInteropabilityAdapterProperty) != DependencyProperty.UnsetValue).FirstOrDefault();

					if (element != null)
					{
						var adapter = WindowInteropabilityHelper.GetWindowInteropabilityAdapter(element);
						var transform = target.TransformToAncestor(element) as Transform;

						return new TransformGroup
						{
							Children =
							{
								transform,
								new TranslateTransform 
								{ 
									X = adapter.AbsoluteLeft, 
									Y = adapter.AbsoluteTop
								}
							}
						};
					}

					return target.TransformToAncestor(GetRootVisual(target));
				}
			}
		}
开发者ID:mparsin,项目名称:Elements,代码行数:55,代码来源:ApplicationHelper.cs


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