XAML-Map-Control/MapControl/WPF/MapPath.WPF.cs
ClemensFischer 560f44a139 Copyright
2025-01-01 18:57:55 +01:00

60 lines
1.7 KiB
C#

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MapControl
{
public partial class MapPath : Shape
{
public MapPath()
{
Stretch = Stretch.None;
}
public static readonly DependencyProperty DataProperty =
DependencyPropertyHelper.AddOwner<MapPath, Geometry>(Path.DataProperty, null,
(path, oldValue, newValue) => path.DataPropertyChanged(oldValue, newValue));
public Geometry Data
{
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
protected override Geometry DefiningGeometry => Data;
private void DataPropertyChanged(Geometry oldData, Geometry newData)
{
// Check if data is actually a new Geometry.
//
if (newData != null && !ReferenceEquals(newData, oldData))
{
if (newData.IsFrozen)
{
Data = newData.Clone(); // DataPropertyChanged called again
}
else
{
UpdateData();
}
}
}
private void SetMapTransform(Matrix matrix)
{
if (Data.Transform is MatrixTransform transform && !transform.IsFrozen)
{
transform.Matrix = matrix;
}
else
{
Data.Transform = new MatrixTransform(matrix);
}
}
}
}