FrameworkElementExtensions

This commit is contained in:
ClemensFischer 2025-11-19 23:34:39 +01:00
parent 24dabf046d
commit d513ea249e
7 changed files with 47 additions and 42 deletions

View file

@ -1,6 +1,4 @@
global using FrameworkElement = Avalonia.Controls.Control;
using Avalonia;
using Avalonia.Media;
using Avalonia;
namespace MapControl
{
@ -24,16 +22,5 @@ namespace MapControl
{
return (MapBase)element.GetValue(ParentMapProperty);
}
public static void SetRenderTransform(FrameworkElement element, Transform transform, double originX = 0d, double originY = 0d)
{
element.RenderTransform = transform;
element.RenderTransformOrigin = new RelativePoint(originX, originY, RelativeUnit.Relative);
}
private static void SetVisible(FrameworkElement element, bool visible)
{
element.IsVisible = visible;
}
}
}

View file

@ -0,0 +1,42 @@
#if AVALONIA
global using FrameworkElement = Avalonia.Controls.Control;
using Avalonia;
using Avalonia.Media;
#elif WPF
using System.Windows;
using System.Windows.Media;
#elif UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#endif
namespace MapControl
{
public static class FrameworkElementExtensions
{
public static void SetRenderTransform(this FrameworkElement element, Transform transform, bool center = false)
{
element.RenderTransform = transform;
#if AVALONIA
element.RenderTransformOrigin = center ? RelativePoint.Center : RelativePoint.TopLeft;
#else
if (center)
{
element.RenderTransformOrigin = new Point(0.5, 0.5);
}
#endif
}
public static void SetVisible(this FrameworkElement element, bool visible)
{
#if AVALONIA
element.IsVisible = visible;
#else
element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
#endif
}
}
}

View file

@ -259,7 +259,7 @@ namespace MapControl
if (GetAutoCollapse(element))
{
SetVisible(element, position.HasValue && parentMap.InsideViewBounds(position.Value));
element.SetVisible(position.HasValue && parentMap.InsideViewBounds(position.Value));
}
if (position.HasValue)
@ -320,7 +320,7 @@ namespace MapControl
}
else if (rotation != 0d)
{
SetRenderTransform(element, new RotateTransform { Angle = rotation }, 0.5, 0.5);
element.SetRenderTransform(new RotateTransform { Angle = rotation }, true);
}
}
}

View file

@ -50,7 +50,7 @@ namespace MapControl
public MapTileLayer()
{
MapPanel.SetRenderTransform(this, new MatrixTransform());
this.SetRenderTransform(new MatrixTransform());
}
public override IReadOnlyCollection<string> SupportedCrsIds { get; } = [WebMercatorProjection.DefaultCrsId];

View file

@ -25,8 +25,7 @@ namespace MapControl
//
public WmtsTileMatrixLayer(WmtsTileMatrix wmtsTileMatrix, int zoomLevel)
{
MapPanel.SetRenderTransform(this, new MatrixTransform());
this.SetRenderTransform(new MatrixTransform());
WmtsTileMatrix = wmtsTileMatrix;
TileMatrix = new TileMatrix(zoomLevel, 1, 1, 0, 0);
}

View file

@ -1,5 +1,4 @@
using System.Windows;
using System.Windows.Media;
namespace MapControl
{
@ -20,16 +19,5 @@ namespace MapControl
{
return (MapBase)element.GetValue(ParentMapProperty);
}
public static void SetRenderTransform(FrameworkElement element, Transform transform, double originX = 0d, double originY = 0d)
{
element.RenderTransform = transform;
element.RenderTransformOrigin = new Point(originX, originY);
}
private static void SetVisible(FrameworkElement element, bool visible)
{
element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
}
}
}

View file

@ -49,16 +49,5 @@ namespace MapControl
return parentMap;
}
public static void SetRenderTransform(FrameworkElement element, Transform transform, double originX = 0d, double originY = 0d)
{
element.RenderTransform = transform;
element.RenderTransformOrigin = new Point(originX, originY);
}
private static void SetVisible(FrameworkElement element, bool visible)
{
element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
}
}
}