Files
Lattice/Lattice.UI.DragDrop.WinUI/Extensions/FrameworkElementExtensions.cs

26 lines
1002 B
C#

using Microsoft.UI.Xaml;
namespace Lattice.UI.DragDrop.WinUI.Helpers;
public static class FrameworkElementExtensions
{
/// <summary>
/// Получает фактические размеры FrameworkElement.
/// </summary>
public static Windows.Foundation.Size GetActualSize(this FrameworkElement element)
{
return new Windows.Foundation.Size(element.ActualWidth, element.ActualHeight);
}
/// <summary>
/// Получает границы элемента в экранных координатах.
/// </summary>
public static Windows.Foundation.Rect GetScreenBounds(this FrameworkElement element)
{
var transform = element.TransformToVisual(null);
var topLeft = transform.TransformPoint(new Windows.Foundation.Point(0, 0));
var bottomRight = transform.TransformPoint(new Windows.Foundation.Point(element.ActualWidth, element.ActualHeight));
return new Windows.Foundation.Rect(topLeft, bottomRight);
}
}