mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Updated MapContentControl, MapItem, MapPath
This commit is contained in:
parent
2dc7431c25
commit
7cfb80520b
18 changed files with 216 additions and 133 deletions
|
|
@ -88,5 +88,26 @@ namespace MapControl
|
|||
{
|
||||
return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue));
|
||||
}
|
||||
|
||||
public static DependencyProperty AddOwner<TOwner, TValue>(
|
||||
DependencyProperty source) where TOwner : DependencyObject
|
||||
{
|
||||
return source.AddOwner(typeof(TOwner));
|
||||
}
|
||||
|
||||
public static DependencyProperty AddOwner<TOwner, TValue>(
|
||||
DependencyProperty source,
|
||||
TValue defaultValue) where TOwner : DependencyObject
|
||||
{
|
||||
return source.AddOwner(typeof(TOwner), new FrameworkPropertyMetadata(defaultValue));
|
||||
}
|
||||
|
||||
public static DependencyProperty AddOwner<TOwner, TValue>(
|
||||
DependencyProperty source,
|
||||
Action<TOwner, TValue, TValue> changed = null) where TOwner : DependencyObject
|
||||
{
|
||||
return source.AddOwner(typeof(TOwner), new FrameworkPropertyMetadata(
|
||||
(o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace MapControl
|
|||
public partial class MapBase
|
||||
{
|
||||
public static readonly DependencyProperty ForegroundProperty =
|
||||
TextElement.ForegroundProperty.AddOwner(typeof(MapBase), new FrameworkPropertyMetadata(Brushes.Black));
|
||||
DependencyPropertyHelper.AddOwner<MapBase, Brush>(TextElement.ForegroundProperty, Brushes.Black);
|
||||
|
||||
public static readonly DependencyProperty AnimationEasingFunctionProperty =
|
||||
DependencyPropertyHelper.Register<MapBase, IEasingFunction>(nameof(AnimationEasingFunction),
|
||||
|
|
|
|||
|
|
@ -1,16 +1,47 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapContentControl
|
||||
/// <summary>
|
||||
/// ContentControl placed on a MapPanel at a geographic location specified by the Location property.
|
||||
/// </summary>
|
||||
public class MapContentControl : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty LocationProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapContentControl, Location>(MapPanel.LocationProperty);
|
||||
|
||||
public static readonly DependencyProperty AutoCollapseProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapContentControl, bool>(MapPanel.AutoCollapseProperty);
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets MapPanel.Location.
|
||||
/// </summary>
|
||||
public Location Location
|
||||
{
|
||||
get => (Location)GetValue(LocationProperty);
|
||||
set => SetValue(LocationProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets MapPanel.AutoCollapse.
|
||||
/// </summary>
|
||||
public bool AutoCollapse
|
||||
{
|
||||
get => (bool)GetValue(AutoCollapseProperty);
|
||||
set => SetValue(AutoCollapseProperty, value);
|
||||
}
|
||||
|
||||
static MapContentControl()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapContentControl), new FrameworkPropertyMetadata(typeof(MapContentControl)));
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Pushpin
|
||||
/// <summary>
|
||||
/// MapContentControl with a Pushpin Style.
|
||||
/// </summary>
|
||||
public class Pushpin : MapContentControl
|
||||
{
|
||||
static Pushpin()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ namespace MapControl
|
|||
public partial class MapGraticule : FrameworkElement, IMapElement
|
||||
{
|
||||
public static readonly DependencyProperty ForegroundProperty =
|
||||
TextElement.ForegroundProperty.AddOwner(typeof(MapGraticule));
|
||||
DependencyPropertyHelper.AddOwner<MapGraticule, Brush>(TextElement.ForegroundProperty);
|
||||
|
||||
public static readonly DependencyProperty FontFamilyProperty =
|
||||
TextElement.FontFamilyProperty.AddOwner(typeof(MapGraticule));
|
||||
DependencyPropertyHelper.AddOwner<MapGraticule, FontFamily>(TextElement.FontFamilyProperty);
|
||||
|
||||
public static readonly DependencyProperty FontSizeProperty =
|
||||
TextElement.FontSizeProperty.AddOwner(typeof(MapGraticule), new FrameworkPropertyMetadata(12d));
|
||||
DependencyPropertyHelper.AddOwner<MapGraticule, double>(TextElement.FontSizeProperty, 12d);
|
||||
|
||||
/// <summary>
|
||||
/// Implements IMapElement.ParentMap.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ namespace MapControl
|
|||
{
|
||||
public partial class MapItem
|
||||
{
|
||||
public static readonly DependencyProperty LocationProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty,
|
||||
(item, oldValue, newValue) => item.UpdateMapTransform());
|
||||
|
||||
public static readonly DependencyProperty AutoCollapseProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapItem, bool>(MapPanel.AutoCollapseProperty);
|
||||
|
||||
static MapItem()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem)));
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ namespace MapControl
|
|||
public partial class MapPath : Shape
|
||||
{
|
||||
public static readonly DependencyProperty DataProperty =
|
||||
Path.DataProperty.AddOwner(typeof(MapPath),
|
||||
new FrameworkPropertyMetadata(null, (o, e) => ((MapPath)o).DataPropertyChanged(e)));
|
||||
DependencyPropertyHelper.AddOwner<MapPath, Geometry>(Path.DataProperty,
|
||||
(path, oldValue, newValue) => path.DataPropertyChanged(oldValue, newValue));
|
||||
|
||||
public Geometry Data
|
||||
{
|
||||
|
|
@ -18,29 +18,15 @@ namespace MapControl
|
|||
|
||||
protected override Geometry DefiningGeometry => Data;
|
||||
|
||||
protected void SetDataTransform(Matrix matrix)
|
||||
{
|
||||
if (Data.Transform is MatrixTransform transform && !transform.IsFrozen)
|
||||
{
|
||||
transform.Matrix = matrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
Data.Transform = new MatrixTransform(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
private void DataPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
private void DataPropertyChanged(Geometry oldValue, Geometry newValue)
|
||||
{
|
||||
// Check if Data is actually a new Geometry.
|
||||
//
|
||||
if (e.NewValue != null && !ReferenceEquals(e.NewValue, e.OldValue))
|
||||
if (newValue != null && !ReferenceEquals(newValue, oldValue))
|
||||
{
|
||||
var data = (Geometry)e.NewValue;
|
||||
|
||||
if (data.IsFrozen)
|
||||
if (newValue.IsFrozen)
|
||||
{
|
||||
Data = data.Clone(); // DataPropertyChanged called again
|
||||
Data = newValue.Clone(); // DataPropertyChanged called again
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue