2022-02-05 15:52:17 +01:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2024-02-03 21:01:53 +01:00
|
|
|
|
// Copyright © 2024 Clemens Fischer
|
2022-02-05 15:52:17 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty ArrowSizeProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(ArrowSize), typeof(Size), typeof(PushpinBorder),
|
|
|
|
|
|
new PropertyMetadata(new Size(10d, 20d), (o, e) => ((PushpinBorder)o).SetBorderMargin()));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty BorderWidthProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(BorderWidth), typeof(double), typeof(PushpinBorder),
|
|
|
|
|
|
new PropertyMetadata(0d, (o, e) => ((PushpinBorder)o).SetBorderMargin()));
|
|
|
|
|
|
|
|
|
|
|
|
private readonly Border border = new Border();
|
|
|
|
|
|
|
|
|
|
|
|
public PushpinBorder()
|
|
|
|
|
|
{
|
|
|
|
|
|
var path = new Path
|
|
|
|
|
|
{
|
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Stretch,
|
|
|
|
|
|
VerticalAlignment = VerticalAlignment.Stretch,
|
|
|
|
|
|
Stretch = Stretch.None
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
path.SetBinding(Shape.FillProperty, new Binding
|
|
|
|
|
|
{
|
2022-08-05 21:30:57 +02:00
|
|
|
|
Path = new PropertyPath(nameof(Background)),
|
2022-02-05 15:52:17 +01:00
|
|
|
|
Source = this
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
path.SetBinding(Shape.StrokeProperty, new Binding
|
|
|
|
|
|
{
|
2022-08-05 21:30:57 +02:00
|
|
|
|
Path = new PropertyPath(nameof(BorderBrush)),
|
2022-02-05 15:52:17 +01:00
|
|
|
|
Source = this
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
path.SetBinding(Shape.StrokeThicknessProperty, new Binding
|
|
|
|
|
|
{
|
2022-08-05 21:30:57 +02:00
|
|
|
|
Path = new PropertyPath(nameof(BorderWidth)),
|
2022-02-05 15:52:17 +01:00
|
|
|
|
Source = this
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
border.SetBinding(PaddingProperty, new Binding
|
|
|
|
|
|
{
|
2022-08-05 21:30:57 +02:00
|
|
|
|
Path = new PropertyPath(nameof(Padding)),
|
2022-02-05 15:52:17 +01:00
|
|
|
|
Source = this
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|