Skip to content

Instantly share code, notes, and snippets.

@BryanWilhite
Created January 16, 2016 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BryanWilhite/ef3967092c63d9e298bf to your computer and use it in GitHub Desktop.
Save BryanWilhite/ef3967092c63d9e298bf to your computer and use it in GitHub Desktop.
WPF VisualExtensions
using System;
using System.Windows;
using System.Windows.Media;
namespace Songhay.Extensions
{
public static class VisualExtensions
{
public static Point GetVisualOrigin(this Visual visual, Visual ancestorVisual)
{
if (visual == null) return default(Point);
if (ancestorVisual == null) throw new ArgumentNullException("ancestorVisual", "The expected ancestor visual is not here.");
var transform = visual.TransformToAncestor(ancestorVisual);
var point = transform.Transform(new Point(0, 0));
return point;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment