Fixed default MapItem style, made ParentMap attached property read-only.

This commit is contained in:
ClemensF 2012-08-10 09:41:59 +02:00
parent 022e246ebe
commit fbeb01fca3
4 changed files with 32 additions and 32 deletions

View file

@ -108,7 +108,7 @@ namespace MapControl
MaxZoomLevel = 20;
AddVisualChild(tileContainer);
TileLayers = new TileLayerCollection();
SetValue(ParentMapProperty, this);
SetValue(ParentMapPropertyKey, this);
Loaded += (o, e) =>
{

View file

@ -14,7 +14,7 @@ namespace MapControl
{
static MapElement()
{
MapPanel.ParentMapProperty.OverrideMetadata(typeof(MapElement),
MapPanel.ParentMapPropertyKey.OverrideMetadata(typeof(MapElement),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
}

View file

@ -16,13 +16,11 @@ namespace MapControl
/// </summary>
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;

View file

@ -11,8 +11,6 @@
</Setter>
</Style>
<Style x:Key="{x:Type map:MapItem}" TargetType="{x:Type map:MapItem}">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type map:MapItem}">