Created
January 16, 2016 03:26
-
-
Save BryanWilhite/ef3967092c63d9e298bf to your computer and use it in GitHub Desktop.
WPF VisualExtensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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