diff --git a/MapControl/Map.cs b/MapControl/Map.cs index 48f6860c..dd7256da 100644 --- a/MapControl/Map.cs +++ b/MapControl/Map.cs @@ -108,7 +108,7 @@ namespace MapControl MaxZoomLevel = 20; AddVisualChild(tileContainer); TileLayers = new TileLayerCollection(); - SetValue(ParentMapProperty, this); + SetValue(ParentMapPropertyKey, this); Loaded += (o, e) => { diff --git a/MapControl/MapElement.cs b/MapControl/MapElement.cs index d31e28ab..2ac29f65 100644 --- a/MapControl/MapElement.cs +++ b/MapControl/MapElement.cs @@ -14,7 +14,7 @@ namespace MapControl { static MapElement() { - MapPanel.ParentMapProperty.OverrideMetadata(typeof(MapElement), + MapPanel.ParentMapPropertyKey.OverrideMetadata(typeof(MapElement), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged)); } diff --git a/MapControl/MapPanel.cs b/MapControl/MapPanel.cs index c84cd822..8150684d 100644 --- a/MapControl/MapPanel.cs +++ b/MapControl/MapPanel.cs @@ -16,13 +16,11 @@ namespace MapControl /// public class MapPanel : Panel { - public static readonly DependencyProperty ParentMapProperty = DependencyProperty.RegisterAttached( + internal static readonly DependencyPropertyKey ParentMapPropertyKey = DependencyProperty.RegisterAttachedReadOnly( "ParentMap", typeof(Map), typeof(MapPanel), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged)); - public static readonly DependencyProperty LocationProperty = DependencyProperty.RegisterAttached( - "Location", typeof(Location), typeof(MapPanel), - new FrameworkPropertyMetadata(LocationPropertyChanged)); + public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty; private static readonly DependencyPropertyKey ViewportPositionPropertyKey = DependencyProperty.RegisterAttachedReadOnly( "ViewportPosition", typeof(ViewportPosition), typeof(MapPanel), @@ -30,6 +28,10 @@ namespace MapControl public static readonly DependencyProperty ViewportPositionProperty = ViewportPositionPropertyKey.DependencyProperty; + public static readonly DependencyProperty LocationProperty = DependencyProperty.RegisterAttached( + "Location", typeof(Location), typeof(MapPanel), + new FrameworkPropertyMetadata(LocationPropertyChanged)); + public MapPanel() { ClipToBounds = true; @@ -45,6 +47,11 @@ namespace MapControl return (Map)element.GetValue(ParentMapProperty); } + public static ViewportPosition GetViewportPosition(UIElement element) + { + return (ViewportPosition)element.GetValue(ViewportPositionProperty); + } + public static Location GetLocation(UIElement element) { return (Location)element.GetValue(LocationProperty); @@ -55,11 +62,6 @@ namespace MapControl element.SetValue(LocationProperty, value); } - public static ViewportPosition GetViewportPosition(UIElement element) - { - return (ViewportPosition)element.GetValue(ViewportPositionProperty); - } - protected override Size MeasureOverride(Size availableSize) { Size infiniteSize = new Size(double.PositiveInfinity, double.PositiveInfinity); @@ -128,6 +130,25 @@ namespace MapControl } } + private static void ViewportPositionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs) + { + UIElement element = obj as UIElement; + + if (element != null) + { + ViewportPosition position = (ViewportPosition)eventArgs.NewValue; + + if (position != null) + { + ArrangeElement(element, position); + } + else + { + element.Arrange(new Rect()); + } + } + } + private static void LocationPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs) { UIElement element = obj as UIElement; @@ -154,25 +175,6 @@ namespace MapControl element.SetValue(ViewportPositionPropertyKey, viewportPosition); } - private static void ViewportPositionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs eventArgs) - { - UIElement element = obj as UIElement; - - if (element != null) - { - ViewportPosition position = (ViewportPosition)eventArgs.NewValue; - - if (position != null) - { - ArrangeElement(element, position); - } - else - { - element.Arrange(new Rect()); - } - } - } - private static bool ArrangeElement(UIElement element, ViewportPosition viewportPosition) { MapPanel panel = VisualTreeHelper.GetParent(element) as MapPanel; diff --git a/MapControl/Themes/Generic.xaml b/MapControl/Themes/Generic.xaml index 99c85ced..1409c6d7 100644 --- a/MapControl/Themes/Generic.xaml +++ b/MapControl/Themes/Generic.xaml @@ -11,8 +11,6 @@