XAML-Map-Control/MapControl/MapElement.cs

52 lines
1.4 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
{
internal interface INotifyParentMapChanged
{
void ParentMapChanged(Map oldParentMap, Map newParentMap);
}
2012-05-04 12:52:20 +02:00
/// <summary>
/// Base class for child elements of a MapPanel.
/// </summary>
2012-04-25 22:02:53 +02:00
public abstract class MapElement : FrameworkElement, INotifyParentMapChanged
{
protected MapElement()
{
HorizontalAlignment = HorizontalAlignment.Stretch;
VerticalAlignment = VerticalAlignment.Stretch;
}
public Map ParentMap
{
get { return MapPanel.GetParentMap(this); }
}
protected abstract void OnViewTransformChanged(Map parentMap);
private void OnViewTransformChanged(object sender, EventArgs eventArgs)
{
OnViewTransformChanged((Map)sender);
}
void INotifyParentMapChanged.ParentMapChanged(Map oldParentMap, Map newParentMap)
{
if (oldParentMap != null)
{
oldParentMap.ViewTransformChanged -= OnViewTransformChanged;
}
if (newParentMap != null)
{
newParentMap.ViewTransformChanged += OnViewTransformChanged;
}
}
}
}