Introduced MapContentControl

This commit is contained in:
ClemensF 2021-01-17 21:39:42 +01:00
parent 207565feba
commit 67e9989327
16 changed files with 218 additions and 143 deletions

View file

@ -110,10 +110,9 @@ namespace MapControl
set { SetValue(StrokeMiterLimitProperty, value); } set { SetValue(StrokeMiterLimitProperty, value); }
} }
protected Binding GetBinding(DependencyProperty property, string propertyName) protected Binding GetBinding(string propertyName)
{ {
return GetBindingExpression(property)?.ParentBinding ?? return new Binding { Source = this, Path = new PropertyPath(propertyName) };
new Binding { Source = this, Path = new PropertyPath(propertyName) };
} }
} }
} }

View file

@ -39,10 +39,10 @@ namespace MapControl
{ {
MinWidth = 100d; MinWidth = 100d;
line.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke))); line.SetBinding(Shape.StrokeProperty, GetBinding(nameof(Stroke)));
line.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness))); line.SetBinding(Shape.StrokeThicknessProperty, GetBinding(nameof(StrokeThickness)));
#if WINDOWS_UWP #if WINDOWS_UWP
label.SetBinding(TextBlock.ForegroundProperty, GetBinding(ForegroundProperty, nameof(Foreground))); label.SetBinding(TextBlock.ForegroundProperty, GetBinding(nameof(Foreground)));
#endif #endif
Children.Add(line); Children.Add(line);
Children.Add(label); Children.Add(label);

View file

@ -12,8 +12,7 @@ namespace MapControl
public partial class MapBase public partial class MapBase
{ {
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register( public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register(
nameof(Foreground), typeof(Brush), typeof(MapBase), nameof(Foreground), typeof(Brush), typeof(MapBase), new PropertyMetadata(new SolidColorBrush(Colors.Black)));
new PropertyMetadata(new SolidColorBrush(Colors.Black)));
public static readonly DependencyProperty CenterProperty = DependencyProperty.Register( public static readonly DependencyProperty CenterProperty = DependencyProperty.Register(
nameof(Center), typeof(Location), typeof(MapBase), nameof(Center), typeof(Location), typeof(MapBase),
@ -50,7 +49,7 @@ namespace MapControl
{ {
// set Background by Style to enable resetting by ClearValue in MapLayerPropertyChanged // set Background by Style to enable resetting by ClearValue in MapLayerPropertyChanged
var style = new Style(typeof(MapBase)); var style = new Style(typeof(MapBase));
style.Setters.Add(new Setter(BackgroundProperty, new SolidColorBrush(Colors.Transparent))); style.Setters.Add(new Setter(BackgroundProperty, new SolidColorBrush(Colors.White)));
Style = style; Style = style;
SizeChanged += (s, e) => SizeChanged += (s, e) =>

View file

@ -0,0 +1,84 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2021 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
namespace MapControl
{
/// <summary>
/// ContentControl placed on a MapPanel at a geographic location specified by the Location property.
/// </summary>
public class MapContentControl : ContentControl
{
public static readonly DependencyProperty AutoCollapseProperty = DependencyProperty.Register(
nameof(AutoCollapse), typeof(bool), typeof(MapContentControl),
new PropertyMetadata(false, (o, e) => MapPanel.SetAutoCollapse((MapContentControl)o, (bool)e.NewValue)));
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
nameof(Location), typeof(Location), typeof(MapContentControl),
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((MapContentControl)o, (Location)e.NewValue)));
public MapContentControl()
{
DefaultStyleKey = typeof(MapContentControl);
MapPanel.InitMapElement(this);
}
/// <summary>
/// Gets/sets MapPanel.AutoCollapse.
/// </summary>
public bool AutoCollapse
{
get { return (bool)GetValue(AutoCollapseProperty); }
set { SetValue(AutoCollapseProperty, value); }
}
/// <summary>
/// Gets/sets MapPanel.Location.
/// </summary>
public Location Location
{
get { return (Location)GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
var map = MapPanel.GetParentMap(this);
if (map != null)
{
if (Background == null)
{
SetBinding(BackgroundProperty, new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Background)) });
}
if (BorderBrush == null)
{
SetBinding(BorderBrushProperty, new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) });
}
if (Foreground == null)
{
SetBinding(ForegroundProperty, new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) });
}
}
}
}
/// <summary>
/// MapContentControl with a Pushpin Style.
/// </summary>
public class Pushpin : MapContentControl
{
public Pushpin()
{
DefaultStyleKey = typeof(Pushpin);
}
}
}

View file

@ -195,7 +195,7 @@
<Compile Include="Matrix.UWP.cs" /> <Compile Include="Matrix.UWP.cs" />
<Compile Include="Point.UWP.cs" /> <Compile Include="Point.UWP.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Pushpin.cs" /> <Compile Include="MapContentControl.UWP.cs" />
<Compile Include="Tile.UWP.cs" /> <Compile Include="Tile.UWP.cs" />
<Compile Include="TileImageLoader.UWP.cs" /> <Compile Include="TileImageLoader.UWP.cs" />
<Compile Include="ImageLoader.UWP.cs" /> <Compile Include="ImageLoader.UWP.cs" />

View file

@ -29,11 +29,11 @@ namespace MapControl
if (path == null) if (path == null)
{ {
path = new Path { Data = new PathGeometry() }; path = new Path { Data = new PathGeometry() };
path.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke))); path.SetBinding(Shape.StrokeProperty, GetBinding(nameof(Stroke)));
path.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness))); path.SetBinding(Shape.StrokeThicknessProperty, GetBinding(nameof(StrokeThickness)));
path.SetBinding(Shape.StrokeDashArrayProperty, GetBinding(StrokeDashArrayProperty, nameof(StrokeDashArray))); path.SetBinding(Shape.StrokeDashArrayProperty, GetBinding(nameof(StrokeDashArray)));
path.SetBinding(Shape.StrokeDashOffsetProperty, GetBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset))); path.SetBinding(Shape.StrokeDashOffsetProperty, GetBinding(nameof(StrokeDashOffset)));
path.SetBinding(Shape.StrokeDashCapProperty, GetBinding(StrokeDashCapProperty, nameof(StrokeDashCap))); path.SetBinding(Shape.StrokeDashCapProperty, GetBinding(nameof(StrokeDashCap)));
Children.Add(path); Children.Add(path);
} }
@ -109,15 +109,15 @@ namespace MapControl
else else
{ {
label = new TextBlock { RenderTransform = new MatrixTransform() }; label = new TextBlock { RenderTransform = new MatrixTransform() };
label.SetBinding(TextBlock.FontSizeProperty, GetBinding(FontSizeProperty, nameof(FontSize))); label.SetBinding(TextBlock.FontSizeProperty, GetBinding(nameof(FontSize)));
label.SetBinding(TextBlock.FontStyleProperty, GetBinding(FontStyleProperty, nameof(FontStyle))); label.SetBinding(TextBlock.FontStyleProperty, GetBinding(nameof(FontStyle)));
label.SetBinding(TextBlock.FontStretchProperty, GetBinding(FontStretchProperty, nameof(FontStretch))); label.SetBinding(TextBlock.FontStretchProperty, GetBinding(nameof(FontStretch)));
label.SetBinding(TextBlock.FontWeightProperty, GetBinding(FontWeightProperty, nameof(FontWeight))); label.SetBinding(TextBlock.FontWeightProperty, GetBinding(nameof(FontWeight)));
label.SetBinding(TextBlock.ForegroundProperty, GetBinding(ForegroundProperty, nameof(Foreground))); label.SetBinding(TextBlock.ForegroundProperty, GetBinding(nameof(Foreground)));
if (FontFamily != null) if (FontFamily != null)
{ {
label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(FontFamilyProperty, nameof(FontFamily))); label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(nameof(FontFamily)));
} }
Children.Add(label); Children.Add(label);

View file

@ -67,14 +67,12 @@ namespace MapControl
{ {
if (Foreground == null) if (Foreground == null)
{ {
SetBinding(ForegroundProperty, SetBinding(ForegroundProperty, new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) });
map.GetBindingExpression(MapBase.ForegroundProperty)?.ParentBinding ??
new Binding { Source = map, Path = new PropertyPath("Foreground") });
} }
if (Stroke == null) if (Stroke == null)
{ {
SetBinding(StrokeProperty, GetBinding(ForegroundProperty, nameof(Foreground))); SetBinding(StrokeProperty, GetBinding(nameof(Foreground)));
} }
} }

View file

@ -1,47 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2021 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace MapControl
{
/// <summary>
/// Pushpin at a geographic location specified by the Location property.
/// </summary>
public class Pushpin : ContentControl
{
public static readonly DependencyProperty AutoCollapseProperty = DependencyProperty.Register(
nameof(AutoCollapse), typeof(bool), typeof(Pushpin),
new PropertyMetadata(false, (o, e) => MapPanel.SetAutoCollapse((Pushpin)o, (bool)e.NewValue)));
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
nameof(Location), typeof(Location), typeof(Pushpin),
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((Pushpin)o, (Location)e.NewValue)));
public Pushpin()
{
DefaultStyleKey = typeof(Pushpin);
MapPanel.InitMapElement(this);
}
/// <summary>
/// Gets/sets MapPanel.AutoCollapse.
/// </summary>
public bool AutoCollapse
{
get { return (bool)GetValue(AutoCollapseProperty); }
set { SetValue(AutoCollapseProperty, value); }
}
/// <summary>
/// Gets/sets MapPanel.Location.
/// </summary>
public Location Location
{
get { return (Location)GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
}
}

View file

@ -1,6 +1,8 @@
<ResourceDictionary <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:map="using:MapControl"> xmlns:map="using:MapControl">
<Style TargetType="map:MapItemsControl"> <Style TargetType="map:MapItemsControl">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -17,32 +19,38 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="map:MapItem">
<Style TargetType="ContentControl" x:Key="ContentControlStyle">
<Setter Property="Foreground" Value="{x:Null}"/>
<Setter Property="Background" Value="{x:Null}"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/> <Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:MapItem"> <ControlTemplate TargetType="ContentControl">
<ContentPresenter Content="{TemplateBinding Content}" <ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="map:Pushpin">
<Style TargetType="map:MapContentControl" BasedOn="{StaticResource ContentControlStyle}"/>
<Style TargetType="map:MapItem" BasedOn="{StaticResource ContentControlStyle}"/>
<Style TargetType="map:Pushpin" BasedOn="{StaticResource ContentControlStyle}">
<Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Bottom"/> <Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="UseLayoutRounding" Value="True"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="Padding" Value="5,3"/>
<Setter Property="Padding" Value="3"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:Pushpin"> <ControlTemplate TargetType="map:Pushpin">
@ -51,14 +59,21 @@
<RowDefinition/> <RowDefinition/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Rectangle Fill="{TemplateBinding Background}"/> <Border Background="{TemplateBinding Background}"
<Path Grid.Row="1" Fill="{TemplateBinding Background}" Data="M 0,-0.5 L 0,16 16,-0.5"/> BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1">
<ContentPresenter Content="{TemplateBinding Content}" <ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</Border>
<Path Grid.Row="1"
Data="M0.5,-1 L0.5,15 10,-1"
Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="1"/>
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>

View file

@ -55,7 +55,7 @@ namespace MapControl
static MapBase() static MapBase()
{ {
ClipToBoundsProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(true)); ClipToBoundsProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(true));
BackgroundProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(Brushes.Transparent)); DefaultStyleKeyProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(typeof(MapBase)));
} }
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)

View file

@ -8,17 +8,17 @@ using System.Windows.Controls;
namespace MapControl namespace MapControl
{ {
/// <summary> /// <summary>
/// Pushpin at a geographic location specified by the Location property. /// ContentControl placed on a MapPanel at a geographic location specified by the Location property.
/// </summary> /// </summary>
public class Pushpin : ContentControl public class MapContentControl : ContentControl
{ {
public static readonly DependencyProperty AutoCollapseProperty = MapPanel.AutoCollapseProperty.AddOwner(typeof(Pushpin)); public static readonly DependencyProperty AutoCollapseProperty = MapPanel.AutoCollapseProperty.AddOwner(typeof(MapContentControl));
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(Pushpin)); public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(MapContentControl));
static Pushpin() static MapContentControl()
{ {
DefaultStyleKeyProperty.OverrideMetadata(typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin))); DefaultStyleKeyProperty.OverrideMetadata(typeof(MapContentControl), new FrameworkPropertyMetadata(typeof(MapContentControl)));
} }
/// <summary> /// <summary>
@ -39,4 +39,15 @@ namespace MapControl
set { SetValue(LocationProperty, value); } set { SetValue(LocationProperty, value); }
} }
} }
/// <summary>
/// MapContentControl with a Pushpin Style.
/// </summary>
public class Pushpin : MapContentControl
{
static Pushpin()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin)));
}
}
} }

View file

@ -2,6 +2,7 @@
// © 2021 Clemens Fischer // © 2021 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Windows; using System.Windows;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Media; using System.Windows.Media;
@ -61,18 +62,14 @@ namespace MapControl
IsHitTestVisibleProperty.OverrideMetadata(typeof(MapOverlay), new FrameworkPropertyMetadata(false)); IsHitTestVisibleProperty.OverrideMetadata(typeof(MapOverlay), new FrameworkPropertyMetadata(false));
} }
public MapOverlay() protected override void OnInitialized(EventArgs e)
{ {
// Set Stroke Binding in a Loaded handler to allow Stroke value from a Style Setter. base.OnInitialized(e);
// SetParentMap is called too early.
Loaded += (s, e) =>
{
if (Stroke == null) if (Stroke == null)
{ {
SetBinding(StrokeProperty, GetBinding(ForegroundProperty, nameof(Foreground))); SetBinding(StrokeProperty, GetBinding(nameof(Foreground)));
} }
};
} }
public Pen CreatePen() public Pen CreatePen()

View file

@ -1,6 +1,13 @@
<ResourceDictionary <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:map="clr-namespace:MapControl"> xmlns:map="clr-namespace:MapControl">
<Style TargetType="map:MapBase">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
</Style>
<Style TargetType="map:MapItemsControl"> <Style TargetType="map:MapItemsControl">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -17,33 +24,36 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="map:MapItem">
<Setter Property="Focusable" Value="False"/> <Style TargetType="ContentControl" x:Key="ContentControlStyle" BasedOn="{StaticResource {x:Type ContentControl}}">
<Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType=map:MapBase}}"/>
<Setter Property="BorderBrush" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType=map:MapBase}}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/> <Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:MapItem"> <ControlTemplate TargetType="ContentControl">
<ContentPresenter Content="{TemplateBinding Content}" <ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="map:Pushpin">
<Style TargetType="map:MapContentControl" BasedOn="{StaticResource ContentControlStyle}"/>
<Style TargetType="map:MapItem" BasedOn="{StaticResource ContentControlStyle}"/>
<Style TargetType="map:Pushpin" BasedOn="{StaticResource ContentControlStyle}">
<Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Bottom"/> <Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="Padding" Value="5,3"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="3"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:Pushpin"> <ControlTemplate TargetType="map:Pushpin">
@ -52,14 +62,21 @@
<RowDefinition/> <RowDefinition/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Rectangle Fill="{TemplateBinding Background}"/> <Border Background="{TemplateBinding Background}"
<Path Grid.Row="1" Fill="{TemplateBinding Background}" Data="M 0,-0.5 L 0,16 16,-0.5"/> BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1">
<ContentPresenter Content="{TemplateBinding Content}" <ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</Border>
<Path Grid.Row="1"
Data="M0.5,-1 L0.5,15 10,-1"
Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="1"/>
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>

View file

@ -23,7 +23,8 @@
<Style x:Key="PointItemStyle" TargetType="map:MapItem"> <Style x:Key="PointItemStyle" TargetType="map:MapItem">
<Setter Property="AutoCollapse" Value="True"/> <Setter Property="AutoCollapse" Value="True"/>
<Setter Property="LocationMemberPath" Value="Location"/> <Setter Property="LocationMemberPath" Value="Location"/>
<Setter Property="Foreground" Value="Black"/> <Setter Property="Foreground" Value="Gray"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:MapItem"> <ControlTemplate TargetType="map:MapItem">
@ -58,7 +59,7 @@
</VisualStateManager.VisualStateGroups> </VisualStateManager.VisualStateGroups>
<Path x:Name="selectedPath" Fill="White" Opacity="0"> <Path x:Name="selectedPath" Fill="White" Opacity="0">
<Path.Data> <Path.Data>
<EllipseGeometry RadiusX="15" RadiusY="15"/> <EllipseGeometry RadiusX="12" RadiusY="12"/>
</Path.Data> </Path.Data>
</Path> </Path>
<Path Fill="Transparent" Stroke="Gray" StrokeThickness="2"> <Path Fill="Transparent" Stroke="Gray" StrokeThickness="2">
@ -67,7 +68,6 @@
</Path.Data> </Path.Data>
</Path> </Path>
<Grid Canvas.Left="15" Canvas.Top="-8"> <Grid Canvas.Left="15" Canvas.Top="-8">
<Rectangle x:Name="labelBackground" Fill="White" Opacity="0.7"/>
<TextBlock Margin="2,0,2,0" Text="{Binding Name}"/> <TextBlock Margin="2,0,2,0" Text="{Binding Name}"/>
</Grid> </Grid>
</Canvas> </Canvas>
@ -80,7 +80,6 @@
<Setter Property="AutoCollapse" Value="True"/> <Setter Property="AutoCollapse" Value="True"/>
<Setter Property="LocationMemberPath" Value="Location"/> <Setter Property="LocationMemberPath" Value="Location"/>
<Setter Property="VerticalAlignment" Value="Bottom"/> <Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:MapItem"> <ControlTemplate TargetType="map:MapItem">
@ -132,7 +131,7 @@
<map:MapItemsControl ItemsSource="{Binding Pushpins}" <map:MapItemsControl ItemsSource="{Binding Pushpins}"
ItemContainerStyle="{StaticResource PushpinItemStyle}"/> ItemContainerStyle="{StaticResource PushpinItemStyle}"/>
<map:Pushpin AutoCollapse="True" Background="Yellow" Foreground="Blue" Content="N 53° 30' E 8° 12'"> <map:Pushpin AutoCollapse="True" Content="N 53° 30' E 8° 12'">
<map:Pushpin.Location> <map:Pushpin.Location>
<map:Location Latitude="53.5" Longitude="8.2"/> <map:Location Latitude="53.5" Longitude="8.2"/>
</map:Pushpin.Location> </map:Pushpin.Location>
@ -140,7 +139,7 @@
</map:Map> </map:Map>
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#BFFFFFFF"> <Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#BFFFFFFF">
<TextBlock Margin="2" FontSize="10" Foreground="Black" <TextBlock Margin="2" FontSize="10"
map:HyperlinkText.InlinesSource="{Binding MapLayers.CurrentMapLayer.Description}"/> map:HyperlinkText.InlinesSource="{Binding MapLayers.CurrentMapLayer.Description}"/>
</Border> </Border>

View file

@ -25,7 +25,6 @@
<EventSetter Event="TouchDown" Handler="MapItemTouchDown"/> <EventSetter Event="TouchDown" Handler="MapItemTouchDown"/>
<Setter Property="AutoCollapse" Value="True"/> <Setter Property="AutoCollapse" Value="True"/>
<Setter Property="Location" Value="{Binding Location}"/> <Setter Property="Location" Value="{Binding Location}"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:MapItem"> <ControlTemplate TargetType="map:MapItem">
@ -36,7 +35,9 @@
<VisualState x:Name="Disabled"/> <VisualState x:Name="Disabled"/>
<VisualState x:Name="MouseOver"> <VisualState x:Name="MouseOver">
<Storyboard> <Storyboard>
<DoubleAnimation Storyboard.TargetName="labelBackground" Storyboard.TargetProperty="Opacity" To="0.7" Duration="0:0:0.1"/> <DoubleAnimation Storyboard.TargetName="hoverPath"
Storyboard.TargetProperty="Opacity"
To="0.7" Duration="0:0:0.1"/>
</Storyboard> </Storyboard>
</VisualState> </VisualState>
</VisualStateGroup> </VisualStateGroup>
@ -44,27 +45,31 @@
<VisualState x:Name="Unselected"/> <VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected"> <VisualState x:Name="Selected">
<Storyboard> <Storyboard>
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.7" Duration="0:0:0.1"/> <DoubleAnimation Storyboard.TargetName="selectedPath"
Storyboard.TargetProperty="Opacity"
To="0.7" Duration="0:0:0.1"/>
</Storyboard> </Storyboard>
</VisualState> </VisualState>
</VisualStateGroup> </VisualStateGroup>
</VisualStateManager.VisualStateGroups> </VisualStateManager.VisualStateGroups>
<Path x:Name="selectedPath" Fill="White" Opacity="0"> <Path x:Name="selectedPath" Fill="White" Opacity="0">
<Path.Data> <Path.Data>
<EllipseGeometry RadiusX="15" RadiusY="15"/> <EllipseGeometry RadiusX="12" RadiusY="12"/>
</Path.Data> </Path.Data>
</Path> </Path>
<Path StrokeThickness="2" Fill="Transparent"> <Path x:Name="hoverPath" StrokeThickness="6" Stroke="White" Opacity="0">
<Path.Stroke> <Path.Data>
<SolidColorBrush Color="Gray"/> <EllipseGeometry RadiusX="8" RadiusY="8"/>
</Path.Stroke> </Path.Data>
</Path>
<Path StrokeThickness="2" Stroke="Gray" Fill="Transparent">
<Path.Data> <Path.Data>
<EllipseGeometry RadiusX="8" RadiusY="8"/> <EllipseGeometry RadiusX="8" RadiusY="8"/>
</Path.Data> </Path.Data>
</Path> </Path>
<Grid Canvas.Left="15" Canvas.Top="-8"> <Grid Canvas.Left="15" Canvas.Top="-8">
<Rectangle x:Name="labelBackground" Fill="White" Opacity="0"/> <local:OutlinedText Margin="1" OutlineThickness="1.5" Text="{Binding Name}"
<local:OutlinedText Margin="1" OutlineThickness="1.5" Text="{Binding Name}"/> Background="{Binding Background, RelativeSource={RelativeSource AncestorType=map:MapBase}}"/>
</Grid> </Grid>
</Canvas> </Canvas>
</ControlTemplate> </ControlTemplate>
@ -82,11 +87,10 @@
<Setter Property="AutoCollapse" Value="True"/> <Setter Property="AutoCollapse" Value="True"/>
<Setter Property="Location" Value="{Binding Location}"/> <Setter Property="Location" Value="{Binding Location}"/>
<Setter Property="VerticalAlignment" Value="Bottom"/> <Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="map:MapItem"> <ControlTemplate TargetType="map:MapItem">
<map:Pushpin Content="{Binding Name}" Foreground="{TemplateBinding Foreground}"/> <map:Pushpin Content="{Binding Name}"/>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
@ -156,7 +160,7 @@
</map:MapPath.Data> </map:MapPath.Data>
</map:MapPath> </map:MapPath>
<map:Pushpin AutoCollapse="True" Location="53.5,8.2" Background="Yellow" Foreground="Blue" Content="N 53°30' E 8°12'"/> <map:Pushpin AutoCollapse="True" Location="53.5,8.2" Content="N 53°30' E 8°12'"/>
</map:Map> </map:Map>
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#AFFFFFFF"> <Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#AFFFFFFF">

View file

@ -117,9 +117,8 @@ namespace WpfApplication
} }
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
GlyphTypeface glyphTypeface;
if (!typeface.TryGetGlyphTypeface(out glyphTypeface)) if (!typeface.TryGetGlyphTypeface(out GlyphTypeface glyphTypeface))
{ {
return false; return false;
} }