本文整理汇总了C#中UIElement.TransformToAncestor方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.TransformToAncestor方法的具体用法?C# UIElement.TransformToAncestor怎么用?C# UIElement.TransformToAncestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIElement
的用法示例。
在下文中一共展示了UIElement.TransformToAncestor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValues
public void SetValues (UIElement SourceControl, String TextToModifyInput, String IDToModifyInput)
{
m_SourceControl = SourceControl;
TextToModify = TextToModifyInput;
IDToModify = IDToModifyInput;
GeneralTransform TransformToVisual = m_SourceControl.TransformToAncestor (Application.Current.MainWindow);
this.WindowStartupLocation = WindowStartupLocation.Manual;
Point StartLocationOnScreen = TransformToVisual.Transform (new Point
(Application.Current.MainWindow.Left, Application.Current.MainWindow.Top));
this.Owner = Application.Current.MainWindow;
this.Left = StartLocationOnScreen.X;
this.Top = StartLocationOnScreen.Y;
}
示例2: GetCurrentLayoutInfo
protected virtual Transform GetCurrentLayoutInfo(UIElement element, out Point arrangePosition)
{
// Figure out where child actually is right now. This is a combination of where the
// panel put it and any render transform currently applied
Point currentPosition = element.TransformToAncestor(this).Transform(new Point());
// See what transform is being applied
Transform currentTransform = element.RenderTransform;
// Compute where the panel actually arranged it to
arrangePosition = currentPosition;
if (currentTransform != null && currentTransform != MatrixTransform.Identity)
{
// Undo any transform we applied
arrangePosition = currentTransform.Inverse.Transform(arrangePosition);
}
return currentTransform;
}
示例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 uiElement)
{
Rect boundingRect = Rect.Empty;
boundingRect = new Rect(uiElement.RenderSize);
// Compute visible portion of the rectangle.
Visual visual = VisualTreeHelper.GetParent(uiElement) as Visual;
while (visual != null && boundingRect != Rect.Empty && boundingRect.Height != 0 && boundingRect.Width != 0)
{
Geometry clipGeometry = VisualTreeHelper.GetClip(visual);
if (clipGeometry != null)
{
GeneralTransform transform = uiElement.TransformToAncestor(visual).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;
}
}
visual = VisualTreeHelper.GetParent(visual) as Visual;
}
return boundingRect;
}
示例4: DumpUIElement
// ------------------------------------------------------------------
// Dump content of UIElement.
// ------------------------------------------------------------------
private static void DumpUIElement(XmlTextWriter writer, UIElement element, Visual parent, bool uiElementsOnly)
{
writer.WriteStartElement(element.GetType().Name);
// Dump layout information
DumpSize(writer, "DesiredSize", element.DesiredSize);
DumpSize(writer, "ComputedSize", element.RenderSize);
Geometry clip = VisualTreeHelper.GetClip(element);
if (clip != null)
{
DumpRect(writer, "Clip.Bounds", clip.Bounds);
}
// Dump transform relative to its parent
GeneralTransform g = element.TransformToAncestor(parent);
Point point = new Point(0, 0);
g.TryTransform(point, out point);
if (point.X != 0 || point.Y != 0)
{
DumpPoint(writer, "Position", point);
}
// Dump element specific information
bool childrenHandled = false;
Type t = element.GetType();
DumpCustomUIElement dumpElement = null;
while(dumpElement==null && t!=null)
{
dumpElement = _elementToDumpHandler[t] as DumpCustomUIElement;
t = t.BaseType;
}
if (dumpElement != null)
{
childrenHandled = dumpElement(writer, element, uiElementsOnly);
}
if (!childrenHandled)
{
if (uiElementsOnly)
{
DumpUIElementChildren(writer, "Children", element);
}
else
{
DumpVisualChildren(writer, "Children", element);
}
}
writer.WriteEndElement();
}
示例5: NudgeToRibbonGroupAxis
/// <summary>
/// Helper method to nudge the vertical postion of keytip,
/// to RibbonGroup's top/bottom axis if applicable.
/// </summary>
private double NudgeToRibbonGroupAxis(UIElement placementTarget, double verticalPosition)
{
if (OwnerRibbonGroup != null)
{
ItemsPresenter itemsPresenter = OwnerRibbonGroup.ItemsPresenter;
if (itemsPresenter != null)
{
GeneralTransform transform = placementTarget.TransformToAncestor(itemsPresenter);
Point targetOrigin = transform.Transform(new Point());
double keyTipTopY = verticalPosition + targetOrigin.Y;
double keyTipCenterY = keyTipTopY;
double keyTipBottomY = keyTipTopY;
if (_keyTipControl != null)
{
keyTipBottomY += _keyTipControl.ActualHeight;
keyTipCenterY += _keyTipControl.ActualHeight / 2;
}
if (DoubleUtil.LessThan(Math.Abs(keyTipTopY), RibbonGroupKeyTipAxisNudgeSpace))
{
// Nudge to top axis
verticalPosition -= (keyTipCenterY - RibbonGroupKeyTipAxisOffset);
}
else if (DoubleUtil.LessThan(Math.Abs(itemsPresenter.ActualHeight - keyTipBottomY), RibbonGroupKeyTipAxisNudgeSpace))
{
// Nudge to bottom axis
double centerOffsetFromGroupBottom = keyTipCenterY - itemsPresenter.ActualHeight;
verticalPosition -= (centerOffsetFromGroupBottom + RibbonGroupKeyTipAxisOffset);
}
}
}
return verticalPosition;
}
示例6: UpdateElementBounds
/// <summary>
/// UpdateElementBounds:
/// Called by InkCanvasSelection.UpdateElementBounds
/// ClipboardProcessor.CopySelectionInXAML
/// </summary>
/// <param name="originalElement"></param>
/// <param name="updatedElement"></param>
/// <param name="transform"></param>
internal void UpdateElementBounds(UIElement originalElement, UIElement updatedElement, Matrix transform)
{
if ( originalElement.DependencyObjectType.Id == updatedElement.DependencyObjectType.Id )
{
// Get the transform from element to Canvas
GeneralTransform elementToCanvas = originalElement.TransformToAncestor(_inkCanvas.InnerCanvas);
//cast to a FrameworkElement, nothing inherits from UIElement besides it right now
FrameworkElement frameworkElement = originalElement as FrameworkElement;
Size size;
Thickness thickness = new Thickness();
if ( frameworkElement == null )
{
// Get the element's render size.
size = originalElement.RenderSize;
}
else
{
size = new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight);
thickness = frameworkElement.Margin;
}
Rect elementBounds = new Rect(0, 0, size.Width, size.Height); // Rect in element space
elementBounds = elementToCanvas.TransformBounds(elementBounds); // Rect in Canvas space
// Now apply the matrix to the element bounds
Rect newBounds = Rect.Transform(elementBounds, transform);
if ( !DoubleUtil.AreClose(elementBounds.Width, newBounds.Width) )
{
if ( frameworkElement == null )
{
Size newSize = originalElement.RenderSize;
newSize.Width = newBounds.Width;
updatedElement.RenderSize = newSize;
}
else
{
((FrameworkElement)updatedElement).Width = newBounds.Width;
}
}
if ( !DoubleUtil.AreClose(elementBounds.Height, newBounds.Height) )
{
if ( frameworkElement == null )
{
Size newSize = originalElement.RenderSize;
newSize.Height = newBounds.Height;
updatedElement.RenderSize = newSize;
}
else
{
( (FrameworkElement)updatedElement ).Height = newBounds.Height;
}
}
double left = InkCanvas.GetLeft(originalElement);
double top = InkCanvas.GetTop(originalElement);
double right = InkCanvas.GetRight(originalElement);
double bottom = InkCanvas.GetBottom(originalElement);
Point originalPosition = new Point(); // Default as (0, 0)
if ( !double.IsNaN(left) )
{
originalPosition.X = left;
}
else if ( !double.IsNaN(right) )
{
originalPosition.X = right;
}
if ( !double.IsNaN(top) )
{
originalPosition.Y = top;
}
else if ( !double.IsNaN(bottom) )
{
originalPosition.Y = bottom;
}
Point newPosition = originalPosition * transform;
if ( !double.IsNaN(left) )
{
InkCanvas.SetLeft(updatedElement, newPosition.X - thickness.Left); // Left wasn't auto
}
else if ( !double.IsNaN(right) )
{
// NOTICE-2005/05/05-WAYNEZEN
// Canvas.RightProperty means the distance between element right side and its parent Canvas
// right side. The same definition is applied to Canvas.BottomProperty
InkCanvas.SetRight(updatedElement, ( right - ( newPosition.X - originalPosition.X ) )); // Right wasn't not auto
//.........这里部分代码省略.........
示例7: ScrollToElement
public void ScrollToElement(UIElement element)
{
GeneralTransform gt = element.TransformToAncestor(this);
}
示例8: GetChildRectangle
/// <summary>
/// Returns the rectangle that defines the outer bounds of a child control.
/// </summary>
/// <param name="uieChild">The child/control for which to return the bounding rectangle.</param>
private Rect GetChildRectangle(UIElement uieChild)
{
//Retrieve the position of the requested child inside the ScrollViewer control
GeneralTransform childTransform = uieChild.TransformToAncestor(this.ScrollOwner);
return childTransform.TransformBounds(new Rect(new Point(0, 0), uieChild.RenderSize));
}
示例9: GetTransformedElementCornerPoints
/// <summary>
/// Private helper that takes an element and transforms it's 4 points
/// into the InkCanvas's space
/// </summary>
private static ElementCornerPoints GetTransformedElementCornerPoints(InkCanvasInnerCanvas canvas, UIElement childElement)
{
Debug.Assert(canvas != null);
Debug.Assert(childElement != null);
Debug.Assert(canvas.CheckAccess());
ElementCornerPoints elementPoints = new ElementCornerPoints();
elementPoints.Set = false;
if (childElement.Visibility != Visibility.Visible)
{
//
// this little one's not worth it...
//
return elementPoints;
}
//
// get the transform from us to our parent InkCavas
//
GeneralTransform parentTransform = childElement.TransformToAncestor(canvas);
//
parentTransform.TryTransform(new Point(0, 0), out elementPoints.UpperLeft);
parentTransform.TryTransform(new Point(childElement.RenderSize.Width, 0), out elementPoints.UpperRight);
parentTransform.TryTransform(new Point(0, childElement.RenderSize.Height), out elementPoints.LowerLeft);
parentTransform.TryTransform(new Point(childElement.RenderSize.Width, childElement.RenderSize.Height), out elementPoints.LowerRight);
elementPoints.Set = true;
return elementPoints;
}
示例10: IsItemInView
internal static bool IsItemInView( UIElement item, UIElement itemsHost )
{
GeneralTransform childTransform = item.TransformToAncestor( itemsHost );
Rect rectangle = childTransform.TransformBounds( new Rect( new Point( 0, 0 ), item.RenderSize ) );
//Check if the elements Rect intersects with that of the scrollviewer's
Rect result = Rect.Intersect( new Rect( new Point( 0, 0 ), itemsHost.RenderSize ), rectangle );
//if result is Empty then the element is not in view
return ( result != Rect.Empty );
}
示例11: GetAbsolutePath
private static Point GetAbsolutePath(UIElement element)
{
return element.TransformToAncestor(window).Transform(new Point(0, 0));
}
示例12: GetElementViewportPosition
/// <summary>
/// Determines if the given element is
/// 1) Completely in the current visible page along the given axis.
/// 2) Partially in the current visible page.
/// 3) Before the current page along the given axis.
/// 4) After the current page along the given axis.
/// fullyVisible parameter specifies if the element needs to be completely
/// in the current visible page along the perpendicular axis (if it is
/// completely in the page along the major axis)
/// </summary>
internal static ElementViewportPosition GetElementViewportPosition(FrameworkElement viewPort,
UIElement element,
FocusNavigationDirection axis,
bool fullyVisible,
out Rect elementRect)
{
elementRect = Rect.Empty;
// If there's no ScrollHost or ItemsHost, the element is not on the page
if (viewPort == null)
{
return ElementViewportPosition.None;
}
if (element == null || !viewPort.IsAncestorOf(element))
{
return ElementViewportPosition.None;
}
Rect viewPortBounds = new Rect(new Point(), viewPort.RenderSize);
Rect elementBounds = new Rect(new Point(), element.RenderSize);
elementBounds = element.TransformToAncestor(viewPort).TransformBounds(elementBounds);
bool northSouth = (axis == FocusNavigationDirection.Up || axis == FocusNavigationDirection.Down);
bool eastWest = (axis == FocusNavigationDirection.Left || axis == FocusNavigationDirection.Right);
elementRect = elementBounds;
// Return true if the element is completely contained within the page along the given axis.
if (fullyVisible)
{
if (viewPortBounds.Contains(elementBounds))
{
return ElementViewportPosition.CompletelyInViewport;
}
}
else
{
if (northSouth)
{
if (DoubleUtil.LessThanOrClose(viewPortBounds.Top, elementBounds.Top)
&& DoubleUtil.LessThanOrClose(elementBounds.Bottom, viewPortBounds.Bottom))
{
return ElementViewportPosition.CompletelyInViewport;
}
}
else if (eastWest)
{
if (DoubleUtil.LessThanOrClose(viewPortBounds.Left, elementBounds.Left)
&& DoubleUtil.LessThanOrClose(elementBounds.Right, viewPortBounds.Right))
{
return ElementViewportPosition.CompletelyInViewport;
}
}
}
if (ElementIntersectsViewport(viewPortBounds, elementBounds))
{
return ElementViewportPosition.PartiallyInViewport;
}
else if ((northSouth && DoubleUtil.LessThanOrClose(elementBounds.Bottom, viewPortBounds.Top)) ||
(eastWest && DoubleUtil.LessThanOrClose(elementBounds.Right, viewPortBounds.Left)))
{
return ElementViewportPosition.BeforeViewport;
}
else if ((northSouth && DoubleUtil.LessThanOrClose(viewPortBounds.Bottom, elementBounds.Top)) ||
(eastWest && DoubleUtil.LessThanOrClose(viewPortBounds.Right, elementBounds.Left)))
{
return ElementViewportPosition.AfterViewport;
}
return ElementViewportPosition.None;
}
示例13: GetTansformedRect
protected Rect GetTansformedRect(UIElement elem)
{
// we clip the top and use only 90% of the parents height.
double height = AvailbleHeight;
var toPoint = elem.TransformToAncestor(this.AdornedElement).Transform(new Point(0, this.TopOffset));
var targetRect = new Rect(toPoint.X, toPoint.Y,
elem.DesiredSize.Width,
Math.Max(height, 1));
return targetRect;
}