本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
示例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];
}
示例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;
}
示例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);
}
示例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));
}
}
}