mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Removed DependencyPropertyHelper.AddOwner
This commit is contained in:
parent
a516d12391
commit
d944058ab3
15 changed files with 72 additions and 125 deletions
|
|
@ -88,26 +88,5 @@ namespace MapControl
|
|||
{
|
||||
return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue));
|
||||
}
|
||||
|
||||
public static DependencyProperty AddOwner<TOwner, TValue>(
|
||||
DependencyProperty property,
|
||||
TValue defaultValue = default,
|
||||
Action<TOwner, TValue, TValue> changed = null)
|
||||
where TOwner : DependencyObject
|
||||
{
|
||||
var metadata = new FrameworkPropertyMetadata();
|
||||
|
||||
if (!Equals(defaultValue, property.GetMetadata(typeof(TOwner)).DefaultValue))
|
||||
{
|
||||
metadata.DefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
if (changed != null)
|
||||
{
|
||||
metadata.PropertyChangedCallback = (o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue);
|
||||
}
|
||||
|
||||
return property.AddOwner(typeof(TOwner), metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace MapControl
|
|||
public partial class MapBase
|
||||
{
|
||||
public static readonly DependencyProperty ForegroundProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapBase, Brush>(TextElement.ForegroundProperty, Brushes.Black);
|
||||
TextElement.ForegroundProperty.AddOwner(typeof(MapBase), new FrameworkPropertyMetadata(Brushes.Black));
|
||||
|
||||
public static readonly DependencyProperty AnimationEasingFunctionProperty =
|
||||
DependencyPropertyHelper.Register<MapBase, IEasingFunction>(nameof(AnimationEasingFunction),
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ namespace MapControl
|
|||
public class MapContentControl : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty AutoCollapseProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapContentControl, bool>(MapPanel.AutoCollapseProperty);
|
||||
MapPanel.AutoCollapseProperty.AddOwner(typeof(MapContentControl));
|
||||
|
||||
public static readonly DependencyProperty LocationProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapContentControl, Location>(MapPanel.LocationProperty);
|
||||
MapPanel.LocationProperty.AddOwner(typeof(MapContentControl));
|
||||
|
||||
static MapContentControl()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,13 +2,22 @@
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapGraticule : Control, IMapElement
|
||||
public partial class MapGraticule : FrameworkElement, IMapElement
|
||||
{
|
||||
public static readonly DependencyProperty ForegroundProperty =
|
||||
TextElement.ForegroundProperty.AddOwner(typeof(MapGraticule));
|
||||
|
||||
public static readonly DependencyProperty FontFamilyProperty =
|
||||
TextElement.FontFamilyProperty.AddOwner(typeof(MapGraticule));
|
||||
|
||||
public static readonly DependencyProperty FontSizeProperty =
|
||||
TextElement.FontSizeProperty.AddOwner(typeof(MapGraticule), new FrameworkPropertyMetadata(12d));
|
||||
|
||||
private MapBase parentMap;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -56,7 +65,7 @@ namespace MapControl
|
|||
|
||||
if (labels.Count > 0)
|
||||
{
|
||||
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
|
||||
var typeface = new Typeface(FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
|
||||
var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;
|
||||
|
||||
foreach (var label in labels)
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ namespace MapControl
|
|||
public partial class MapItem
|
||||
{
|
||||
public static readonly DependencyProperty AutoCollapseProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapItem, bool>(MapPanel.AutoCollapseProperty);
|
||||
MapPanel.AutoCollapseProperty.AddOwner(typeof(MapItem));
|
||||
|
||||
public static readonly DependencyProperty LocationProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty, null,
|
||||
(item, oldValue, newValue) => item.UpdateMapTransform());
|
||||
MapPanel.LocationProperty.AddOwner(typeof(MapItem),
|
||||
new FrameworkPropertyMetadata(null, (o, e) => ((MapItem)o).UpdateMapTransform()));
|
||||
|
||||
static MapItem()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,14 +6,9 @@ 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));
|
||||
Path.DataProperty.AddOwner(typeof(MapPath),
|
||||
new FrameworkPropertyMetadata(null, (o, e) => ((MapPath)o).DataPropertyChanged(e)));
|
||||
|
||||
public Geometry Data
|
||||
{
|
||||
|
|
@ -23,15 +18,17 @@ namespace MapControl
|
|||
|
||||
protected override Geometry DefiningGeometry => Data;
|
||||
|
||||
private void DataPropertyChanged(Geometry oldData, Geometry newData)
|
||||
private void DataPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
// Check if data is actually a new Geometry.
|
||||
// Check if Data is actually a new Geometry.
|
||||
//
|
||||
if (newData != null && !ReferenceEquals(newData, oldData))
|
||||
if (e.NewValue != null && !ReferenceEquals(e.NewValue, e.OldValue))
|
||||
{
|
||||
if (newData.IsFrozen)
|
||||
var data = (Geometry)e.NewValue;
|
||||
|
||||
if (data.IsFrozen)
|
||||
{
|
||||
Data = newData.Clone(); // DataPropertyChanged called again
|
||||
Data = data.Clone(); // DataPropertyChanged called again
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue