2025-02-27 18:46:32 +01:00
|
|
|
|
using System.Windows;
|
2018-02-09 17:43:47 +01:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2024-05-26 09:49:00 +02:00
|
|
|
|
public partial class MapPath : Shape
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
2023-01-24 16:22:02 +01:00
|
|
|
|
public MapPath()
|
|
|
|
|
|
{
|
|
|
|
|
|
Stretch = Stretch.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-23 18:08:14 +02:00
|
|
|
|
public static readonly DependencyProperty DataProperty =
|
2024-07-05 09:20:30 +02:00
|
|
|
|
DependencyPropertyHelper.AddOwner<MapPath, Geometry>(Path.DataProperty, null,
|
2024-05-23 18:08:14 +02:00
|
|
|
|
(path, oldValue, newValue) => path.DataPropertyChanged(oldValue, newValue));
|
2020-03-28 21:53:38 +01:00
|
|
|
|
|
|
|
|
|
|
public Geometry Data
|
|
|
|
|
|
{
|
2022-08-06 10:40:59 +02:00
|
|
|
|
get => (Geometry)GetValue(DataProperty);
|
|
|
|
|
|
set => SetValue(DataProperty, value);
|
2020-03-28 21:53:38 +01:00
|
|
|
|
}
|
2018-02-09 17:43:47 +01:00
|
|
|
|
|
2022-08-06 10:40:59 +02:00
|
|
|
|
protected override Geometry DefiningGeometry => Data;
|
2018-02-09 17:43:47 +01:00
|
|
|
|
|
2024-05-23 18:08:14 +02:00
|
|
|
|
private void DataPropertyChanged(Geometry oldData, Geometry newData)
|
2022-11-03 20:10:17 +01:00
|
|
|
|
{
|
2023-01-25 14:29:27 +01:00
|
|
|
|
// Check if data is actually a new Geometry.
|
2022-11-30 22:18:45 +01:00
|
|
|
|
//
|
2024-05-23 18:08:14 +02:00
|
|
|
|
if (newData != null && !ReferenceEquals(newData, oldData))
|
2022-11-03 20:10:17 +01:00
|
|
|
|
{
|
2024-05-23 18:08:14 +02:00
|
|
|
|
if (newData.IsFrozen)
|
2022-11-03 20:10:17 +01:00
|
|
|
|
{
|
2024-05-23 18:08:14 +02:00
|
|
|
|
Data = newData.Clone(); // DataPropertyChanged called again
|
2022-11-03 20:10:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-05-23 18:08:14 +02:00
|
|
|
|
UpdateData();
|
2022-11-03 20:10:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-23 18:42:10 +01:00
|
|
|
|
private void SetMapTransform(Matrix matrix)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Data.Transform is MatrixTransform transform && !transform.IsFrozen)
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.Matrix = matrix;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Data.Transform = new MatrixTransform(matrix);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|