XAML-Map-Control/MapControl/WinUI/PushpinBorder.WinUI.cs

78 lines
2.4 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using Windows.Foundation;
2024-05-22 11:25:32 +02:00
#if UWP
2022-02-05 15:52:17 +01:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
2024-05-22 11:25:32 +02:00
#else
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
2022-02-05 15:52:17 +01:00
#endif
namespace MapControl
{
[ContentProperty(Name = "Child")]
public partial class PushpinBorder : UserControl
{
2024-05-23 18:08:14 +02:00
public static readonly DependencyProperty ArrowSizeProperty =
2024-05-23 18:22:52 +02:00
DependencyPropertyHelper.Register<PushpinBorder, Size>(nameof(ArrowSize), new Size(10d, 20d),
2024-05-23 18:08:14 +02:00
(border, oldValue, newValue) => border.SetBorderMargin());
2022-02-05 15:52:17 +01:00
2024-05-23 18:08:14 +02:00
public static readonly DependencyProperty BorderWidthProperty =
2024-05-23 18:22:52 +02:00
DependencyPropertyHelper.Register<PushpinBorder, double>(nameof(BorderWidth), 0d,
2024-05-23 18:08:14 +02:00
(border, oldValue, newValue) => border.SetBorderMargin());
2022-02-05 15:52:17 +01:00
private readonly Border border = new Border();
public PushpinBorder()
{
var path = new Path
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Stretch = Stretch.None
};
2025-06-06 11:39:26 +02:00
path.SetBinding(Shape.FillProperty,
new Binding { Source = this, Path = new PropertyPath(nameof(Background)) });
2022-02-05 15:52:17 +01:00
2025-06-06 11:39:26 +02:00
path.SetBinding(Shape.StrokeProperty,
new Binding { Source = this, Path = new PropertyPath(nameof(BorderBrush)) });
2022-02-05 15:52:17 +01:00
2025-06-06 11:39:26 +02:00
path.SetBinding(Shape.StrokeThicknessProperty,
new Binding { Source = this, Path = new PropertyPath(nameof(BorderWidth)) });
border.SetBinding(PaddingProperty,
new Binding { Source = this, Path = new PropertyPath(nameof(Padding)) });
2022-02-05 15:52:17 +01:00
SetBorderMargin();
var grid = new Grid();
grid.Children.Add(path);
grid.Children.Add(border);
Content = grid;
SizeChanged += (s, e) => path.Data = BuildGeometry();
}
public UIElement Child
{
2022-08-06 10:40:59 +02:00
get => border.Child;
set => border.Child = value;
2022-02-05 15:52:17 +01:00
}
private void SetBorderMargin()
{
border.Margin = new Thickness(
BorderWidth, BorderWidth, BorderWidth, BorderWidth + ArrowSize.Height);
}
}
}