XAML-Map-Control/MapControl/WPF/MapPath.WPF.cs

53 lines
1.5 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MapControl
{
2024-05-26 09:49:00 +02:00
public partial class MapPath : Shape
{
2024-05-23 18:08:14 +02:00
public static readonly DependencyProperty DataProperty =
Path.DataProperty.AddOwner(typeof(MapPath),
new FrameworkPropertyMetadata(null, (o, e) => ((MapPath)o).DataPropertyChanged(e)));
public Geometry Data
{
2022-08-06 10:40:59 +02:00
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
2022-08-06 10:40:59 +02:00
protected override Geometry DefiningGeometry => Data;
private void DataPropertyChanged(DependencyPropertyChangedEventArgs e)
2022-11-03 20:10:17 +01:00
{
// Check if Data is actually a new Geometry.
2022-11-30 22:18:45 +01:00
//
if (e.NewValue != null && !ReferenceEquals(e.NewValue, e.OldValue))
2022-11-03 20:10:17 +01:00
{
var data = (Geometry)e.NewValue;
if (data.IsFrozen)
2022-11-03 20:10:17 +01:00
{
Data = data.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);
}
}
}
}