mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Introduced MapContentControl
This commit is contained in:
parent
207565feba
commit
67e9989327
16 changed files with 218 additions and 143 deletions
|
|
@ -12,8 +12,7 @@ namespace MapControl
|
|||
public partial class MapBase
|
||||
{
|
||||
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register(
|
||||
nameof(Foreground), typeof(Brush), typeof(MapBase),
|
||||
new PropertyMetadata(new SolidColorBrush(Colors.Black)));
|
||||
nameof(Foreground), typeof(Brush), typeof(MapBase), new PropertyMetadata(new SolidColorBrush(Colors.Black)));
|
||||
|
||||
public static readonly DependencyProperty CenterProperty = DependencyProperty.Register(
|
||||
nameof(Center), typeof(Location), typeof(MapBase),
|
||||
|
|
@ -50,7 +49,7 @@ namespace MapControl
|
|||
{
|
||||
// set Background by Style to enable resetting by ClearValue in MapLayerPropertyChanged
|
||||
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;
|
||||
|
||||
SizeChanged += (s, e) =>
|
||||
|
|
|
|||
84
MapControl/UWP/MapContentControl.UWP.cs
Normal file
84
MapControl/UWP/MapContentControl.UWP.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@
|
|||
<Compile Include="Matrix.UWP.cs" />
|
||||
<Compile Include="Point.UWP.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Pushpin.cs" />
|
||||
<Compile Include="MapContentControl.UWP.cs" />
|
||||
<Compile Include="Tile.UWP.cs" />
|
||||
<Compile Include="TileImageLoader.UWP.cs" />
|
||||
<Compile Include="ImageLoader.UWP.cs" />
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ namespace MapControl
|
|||
if (path == null)
|
||||
{
|
||||
path = new Path { Data = new PathGeometry() };
|
||||
path.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke)));
|
||||
path.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness)));
|
||||
path.SetBinding(Shape.StrokeDashArrayProperty, GetBinding(StrokeDashArrayProperty, nameof(StrokeDashArray)));
|
||||
path.SetBinding(Shape.StrokeDashOffsetProperty, GetBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset)));
|
||||
path.SetBinding(Shape.StrokeDashCapProperty, GetBinding(StrokeDashCapProperty, nameof(StrokeDashCap)));
|
||||
path.SetBinding(Shape.StrokeProperty, GetBinding(nameof(Stroke)));
|
||||
path.SetBinding(Shape.StrokeThicknessProperty, GetBinding(nameof(StrokeThickness)));
|
||||
path.SetBinding(Shape.StrokeDashArrayProperty, GetBinding(nameof(StrokeDashArray)));
|
||||
path.SetBinding(Shape.StrokeDashOffsetProperty, GetBinding(nameof(StrokeDashOffset)));
|
||||
path.SetBinding(Shape.StrokeDashCapProperty, GetBinding(nameof(StrokeDashCap)));
|
||||
Children.Add(path);
|
||||
}
|
||||
|
||||
|
|
@ -109,15 +109,15 @@ namespace MapControl
|
|||
else
|
||||
{
|
||||
label = new TextBlock { RenderTransform = new MatrixTransform() };
|
||||
label.SetBinding(TextBlock.FontSizeProperty, GetBinding(FontSizeProperty, nameof(FontSize)));
|
||||
label.SetBinding(TextBlock.FontStyleProperty, GetBinding(FontStyleProperty, nameof(FontStyle)));
|
||||
label.SetBinding(TextBlock.FontStretchProperty, GetBinding(FontStretchProperty, nameof(FontStretch)));
|
||||
label.SetBinding(TextBlock.FontWeightProperty, GetBinding(FontWeightProperty, nameof(FontWeight)));
|
||||
label.SetBinding(TextBlock.ForegroundProperty, GetBinding(ForegroundProperty, nameof(Foreground)));
|
||||
label.SetBinding(TextBlock.FontSizeProperty, GetBinding(nameof(FontSize)));
|
||||
label.SetBinding(TextBlock.FontStyleProperty, GetBinding(nameof(FontStyle)));
|
||||
label.SetBinding(TextBlock.FontStretchProperty, GetBinding(nameof(FontStretch)));
|
||||
label.SetBinding(TextBlock.FontWeightProperty, GetBinding(nameof(FontWeight)));
|
||||
label.SetBinding(TextBlock.ForegroundProperty, GetBinding(nameof(Foreground)));
|
||||
|
||||
if (FontFamily != null)
|
||||
{
|
||||
label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(FontFamilyProperty, nameof(FontFamily)));
|
||||
label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(nameof(FontFamily)));
|
||||
}
|
||||
|
||||
Children.Add(label);
|
||||
|
|
|
|||
|
|
@ -67,14 +67,12 @@ namespace MapControl
|
|||
{
|
||||
if (Foreground == null)
|
||||
{
|
||||
SetBinding(ForegroundProperty,
|
||||
map.GetBindingExpression(MapBase.ForegroundProperty)?.ParentBinding ??
|
||||
new Binding { Source = map, Path = new PropertyPath("Foreground") });
|
||||
SetBinding(ForegroundProperty, new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) });
|
||||
}
|
||||
|
||||
if (Stroke == null)
|
||||
{
|
||||
SetBinding(StrokeProperty, GetBinding(ForegroundProperty, nameof(Foreground)));
|
||||
SetBinding(StrokeProperty, GetBinding(nameof(Foreground)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:map="using:MapControl">
|
||||
|
||||
<Style TargetType="map:MapItemsControl">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
|
|
@ -17,32 +19,38 @@
|
|||
</Setter.Value>
|
||||
</Setter>
|
||||
</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="VerticalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="map:MapItem">
|
||||
<ControlTemplate TargetType="ContentControl">
|
||||
<ContentPresenter Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Margin="{TemplateBinding Padding}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</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="VerticalAlignment" Value="Bottom"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Padding" Value="3"/>
|
||||
<Setter Property="Foreground" Value="Black"/>
|
||||
<Setter Property="Background" Value="White"/>
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
<Setter Property="Padding" Value="5,3"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="map:Pushpin">
|
||||
|
|
@ -51,14 +59,21 @@
|
|||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle Fill="{TemplateBinding Background}"/>
|
||||
<Path Grid.Row="1" Fill="{TemplateBinding Background}" Data="M 0,-0.5 L 0,16 16,-0.5"/>
|
||||
<ContentPresenter Content="{TemplateBinding Content}"
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="1">
|
||||
<ContentPresenter Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
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>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue