XAML-Map-Control/MapControl/Shared/UIElementExtension.cs

43 lines
1 KiB
C#
Raw Normal View History

2026-01-06 07:54:45 +01:00
#if WPF
2025-11-19 23:34:39 +01:00
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;
2026-01-06 07:54:45 +01:00
#elif AVALONIA
global using UIElement = Avalonia.Controls.Control;
global using FrameworkElement = Avalonia.Controls.Control;
using Avalonia;
using Avalonia.Media;
2025-11-19 23:34:39 +01:00
#endif
2026-04-13 17:14:49 +02:00
namespace MapControl;
public static class UIElementExtension
2025-11-19 23:34:39 +01:00
{
2026-04-13 17:14:49 +02:00
public static void SetRenderTransform(this UIElement element, Transform transform, bool center = false)
2025-11-19 23:34:39 +01:00
{
2026-04-13 17:14:49 +02:00
element.RenderTransform = transform;
2025-11-19 23:34:39 +01:00
#if AVALONIA
2026-04-13 17:14:49 +02:00
element.RenderTransformOrigin = center ? RelativePoint.Center : RelativePoint.TopLeft;
2025-11-19 23:34:39 +01:00
#else
2026-04-13 17:14:49 +02:00
if (center)
{
element.RenderTransformOrigin = new Point(0.5, 0.5);
2025-11-19 23:34:39 +01:00
}
2026-04-13 17:14:49 +02:00
#endif
}
2025-11-19 23:34:39 +01:00
2026-04-13 17:14:49 +02:00
public static void SetVisible(this UIElement element, bool visible)
{
2025-11-19 23:34:39 +01:00
#if AVALONIA
2026-04-13 17:14:49 +02:00
element.IsVisible = visible;
2025-11-19 23:34:39 +01:00
#else
2026-04-13 17:14:49 +02:00
element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
2025-11-19 23:34:39 +01:00
#endif
}
}