XAML-Map-Control/MapControl/MapElement.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2012-05-04 12:52:20 +02:00
// WPF MapControl - http://wpfmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2012-04-25 22:02:53 +02:00
using System.Windows;
namespace MapControl
{
2012-05-04 12:52:20 +02:00
/// <summary>
/// Base class for child elements of a MapPanel.
/// </summary>
2012-08-08 20:42:06 +02:00
public abstract class MapElement : FrameworkElement
2012-04-25 22:02:53 +02:00
{
2012-08-08 20:42:06 +02:00
static MapElement()
{
MapPanel.ParentMapPropertyKey.OverrideMetadata(
typeof(MapElement),
2012-08-08 20:42:06 +02:00
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
}
public MapBase ParentMap
2012-04-25 22:02:53 +02:00
{
get { return MapPanel.GetParentMap(this); }
}
2012-08-08 20:42:06 +02:00
protected abstract void OnViewportChanged();
2012-04-25 22:02:53 +02:00
private void OnViewportChanged(object sender, EventArgs e)
{
OnViewportChanged();
}
private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
2012-04-25 22:02:53 +02:00
{
2012-08-08 20:42:06 +02:00
MapElement mapElement = obj as MapElement;
2012-04-25 22:02:53 +02:00
2012-08-08 20:42:06 +02:00
if (mapElement != null)
2012-04-25 22:02:53 +02:00
{
MapBase oldParentMap = e.OldValue as MapBase;
MapBase newParentMap = e.NewValue as MapBase;
2012-08-08 20:42:06 +02:00
if (oldParentMap != null)
{
oldParentMap.ViewportChanged -= mapElement.OnViewportChanged;
}
if (newParentMap != null)
{
newParentMap.ViewportChanged += mapElement.OnViewportChanged;
}
2012-04-25 22:02:53 +02:00
}
}
}
}