Version 4.9.0: Reworked MapPanel child arrangement.

This commit is contained in:
ClemensF 2018-05-01 12:45:19 +02:00
parent ea2cd438fa
commit 452e2a5454
9 changed files with 104 additions and 172 deletions

View file

@ -46,7 +46,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.0.8</Version> <Version>6.1.2</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -49,10 +49,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Data.SQLite"> <PackageReference Include="Microsoft.Data.SQLite">
<Version>2.0.0</Version> <Version>2.0.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.0.8</Version> <Version>6.1.2</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -10,7 +10,9 @@ using Windows.UI.Xaml.Media;
#else #else
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes;
#endif #endif
namespace MapControl namespace MapControl
@ -20,10 +22,15 @@ namespace MapControl
/// </summary> /// </summary>
public partial class MapOverlay : MapPanel public partial class MapOverlay : MapPanel
{ {
public double FontSize public MapOverlay()
{ {
get { return (double)GetValue(FontSizeProperty); } Loaded += (s, e) =>
set { SetValue(FontSizeProperty, value); } {
if (Stroke == null)
{
SetBinding(StrokeProperty, GetBinding(ForegroundProperty, nameof(Foreground)));
}
};
} }
public FontFamily FontFamily public FontFamily FontFamily
@ -32,6 +39,12 @@ namespace MapControl
set { SetValue(FontFamilyProperty, value); } set { SetValue(FontFamilyProperty, value); }
} }
public double FontSize
{
get { return (double)GetValue(FontSizeProperty); }
set { SetValue(FontSizeProperty, value); }
}
public FontStyle FontStyle public FontStyle FontStyle
{ {
get { return (FontStyle)GetValue(FontStyleProperty); } get { return (FontStyle)GetValue(FontStyleProperty); }
@ -110,103 +123,7 @@ namespace MapControl
set { SetValue(StrokeMiterLimitProperty, value); } set { SetValue(StrokeMiterLimitProperty, value); }
} }
public Binding FontSizeBinding protected Binding GetBinding(DependencyProperty property, string propertyName)
{
get { return GetBinding(FontSizeProperty, nameof(FontSize)); }
}
public Binding FontFamilyBinding
{
get { return GetBinding(FontFamilyProperty, nameof(FontFamily)); }
}
public Binding FontStyleBinding
{
get { return GetBinding(FontStyleProperty, nameof(FontStyle)); }
}
public Binding FontStretchBinding
{
get { return GetBinding(FontStretchProperty, nameof(FontStretch)); }
}
public Binding FontWeightBinding
{
get { return GetBinding(FontWeightProperty, nameof(FontWeight)); }
}
public Binding ForegroundBinding
{
get { return GetBinding(ForegroundProperty, nameof(Foreground)); }
}
public Binding StrokeBinding
{
get { return GetBinding(StrokeProperty, nameof(Stroke)); }
}
public Binding StrokeThicknessBinding
{
get { return GetBinding(StrokeThicknessProperty, nameof(StrokeThickness)); }
}
public Binding StrokeDashArrayBinding
{
get { return GetBinding(StrokeDashArrayProperty, nameof(StrokeDashArray)); }
}
public Binding StrokeDashOffsetBinding
{
get { return GetBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset)); }
}
public Binding StrokeDashCapBinding
{
get { return GetBinding(StrokeDashCapProperty, nameof(StrokeDashCap)); }
}
public Binding StrokeStartLineCapBinding
{
get { return GetBinding(StrokeStartLineCapProperty, nameof(StrokeStartLineCap)); }
}
public Binding StrokeEndLineCapBinding
{
get { return GetBinding(StrokeEndLineCapProperty, nameof(StrokeEndLineCap)); }
}
public Binding StrokeLineJoinBinding
{
get { return GetBinding(StrokeLineJoinProperty, nameof(StrokeLineJoin)); }
}
public Binding StrokeMiterLimitBinding
{
get { return GetBinding(StrokeMiterLimitProperty, nameof(StrokeMiterLimit)); }
}
protected override void SetParentMap(MapBase map)
{
if (map != null)
{
#if WINDOWS_UWP
if (Foreground == null)
{
SetBinding(ForegroundProperty,
map.GetBindingExpression(MapBase.ForegroundProperty)?.ParentBinding ??
new Binding { Source = map, Path = new PropertyPath("Foreground") });
}
#endif
if (Stroke == null)
{
SetBinding(StrokeProperty, ForegroundBinding);
}
}
base.SetParentMap(map);
}
private Binding GetBinding(DependencyProperty property, string propertyName)
{ {
return GetBindingExpression(property)?.ParentBinding ?? return GetBindingExpression(property)?.ParentBinding ??
new Binding { Source = this, Path = new PropertyPath(propertyName) }; new Binding { Source = this, Path = new PropertyPath(propertyName) };

View file

@ -92,6 +92,16 @@ namespace MapControl
} }
} }
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
OnViewportChanged(e);
}
protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
{
InvalidateArrange();
}
protected override Size MeasureOverride(Size availableSize) protected override Size MeasureOverride(Size availableSize)
{ {
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity); availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
@ -131,16 +141,6 @@ namespace MapControl
return finalSize; return finalSize;
} }
protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
{
InvalidateArrange();
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
OnViewportChanged(e);
}
private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{ {
var mapElement = obj as IMapElement; var mapElement = obj as IMapElement;

View file

@ -28,21 +28,22 @@ namespace MapControl
public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register( public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register(
nameof(Padding), typeof(Thickness), typeof(MapScale), new PropertyMetadata(new Thickness(4))); nameof(Padding), typeof(Thickness), typeof(MapScale), new PropertyMetadata(new Thickness(4)));
private TextBlock label = new TextBlock(); private readonly Polyline line = new Polyline();
private Polyline line = new Polyline();
private readonly TextBlock label = new TextBlock
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
TextAlignment = TextAlignment.Center
};
public MapScale() public MapScale()
{ {
IsHitTestVisible = false; IsHitTestVisible = false;
MinWidth = 100d; MinWidth = 100d;
label.HorizontalAlignment = HorizontalAlignment.Left; line.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke)));
label.VerticalAlignment = VerticalAlignment.Top; line.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness)));
label.TextAlignment = TextAlignment.Center;
label.SetBinding(TextBlock.ForegroundProperty, ForegroundBinding);
line.SetBinding(Shape.StrokeProperty, StrokeBinding);
line.SetBinding(Shape.StrokeThicknessProperty, StrokeThicknessBinding);
Children.Add(line); Children.Add(line);
Children.Add(label); Children.Add(label);
@ -91,18 +92,8 @@ namespace MapControl
new Point(x2, y2), new Point(x2, y2),
new Point(x2, y1) new Point(x2, y1)
}; };
line.Measure(size); line.Measure(size);
if (FontFamily != null)
{
label.FontFamily = FontFamily;
}
label.FontSize = FontSize;
label.FontStyle = FontStyle;
label.FontStretch = FontStretch;
label.FontWeight = FontWeight;
label.Text = length >= 1000d ? string.Format("{0:0} km", length / 1000d) : string.Format("{0:0} m", length); label.Text = length >= 1000d ? string.Format("{0:0} km", length / 1000d) : string.Format("{0:0} m", length);
label.Width = size.Width; label.Width = size.Width;
label.Height = size.Height; label.Height = size.Height;

View file

@ -168,7 +168,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.0.8</Version> <Version>6.1.2</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -31,11 +31,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, StrokeBinding); path.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke)));
path.SetBinding(Shape.StrokeThicknessProperty, StrokeThicknessBinding); path.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness)));
path.SetBinding(Shape.StrokeDashArrayProperty, StrokeDashArrayBinding); path.SetBinding(Shape.StrokeDashArrayProperty, GetBinding(StrokeDashArrayProperty, nameof(StrokeDashArray)));
path.SetBinding(Shape.StrokeDashOffsetProperty, StrokeDashOffsetBinding); path.SetBinding(Shape.StrokeDashOffsetProperty, GetBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset)));
path.SetBinding(Shape.StrokeDashCapProperty, StrokeDashCapBinding); path.SetBinding(Shape.StrokeDashCapProperty, GetBinding(StrokeDashCapProperty, nameof(StrokeDashCap)));
Children.Add(path); Children.Add(path);
} }
@ -118,13 +118,13 @@ namespace MapControl
label = new TextBlock { RenderTransform = renderTransform }; label = new TextBlock { RenderTransform = renderTransform };
if (FontFamily != null) if (FontFamily != null)
{ {
label.SetBinding(TextBlock.FontFamilyProperty, FontFamilyBinding); label.SetBinding(TextBlock.FontFamilyProperty, GetBinding(FontFamilyProperty, nameof(FontFamily)));
} }
label.SetBinding(TextBlock.FontSizeProperty, FontSizeBinding); label.SetBinding(TextBlock.FontSizeProperty, GetBinding(FontSizeProperty, nameof(FontSize)));
label.SetBinding(TextBlock.FontStyleProperty, FontStyleBinding); label.SetBinding(TextBlock.FontStyleProperty, GetBinding(FontStyleProperty, nameof(FontStyle)));
label.SetBinding(TextBlock.FontStretchProperty, FontStretchBinding); label.SetBinding(TextBlock.FontStretchProperty, GetBinding(FontStretchProperty, nameof(FontStretch)));
label.SetBinding(TextBlock.FontWeightProperty, FontWeightBinding); label.SetBinding(TextBlock.FontWeightProperty, GetBinding(FontWeightProperty, nameof(FontWeight)));
label.SetBinding(TextBlock.ForegroundProperty, ForegroundBinding); label.SetBinding(TextBlock.ForegroundProperty, GetBinding(ForegroundProperty, nameof(Foreground)));
Children.Add(label); Children.Add(label);
} }

View file

@ -4,18 +4,19 @@
using Windows.UI.Text; using Windows.UI.Text;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media;
namespace MapControl namespace MapControl
{ {
public partial class MapOverlay public partial class MapOverlay
{ {
public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register(
nameof(FontSize), typeof(double), typeof(MapOverlay), new PropertyMetadata(12d));
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register( public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(
nameof(FontFamily), typeof(FontFamily), typeof(MapOverlay), new PropertyMetadata(null)); nameof(FontFamily), typeof(FontFamily), typeof(MapOverlay), new PropertyMetadata(null));
public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register(
nameof(FontSize), typeof(double), typeof(MapOverlay), new PropertyMetadata(12d));
public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register( public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register(
nameof(FontStyle), typeof(FontStyle), typeof(MapOverlay), new PropertyMetadata(FontStyle.Normal)); nameof(FontStyle), typeof(FontStyle), typeof(MapOverlay), new PropertyMetadata(FontStyle.Normal));
@ -54,5 +55,17 @@ namespace MapControl
public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyProperty.Register(
nameof(StrokeMiterLimit), typeof(double), typeof(MapOverlay), new PropertyMetadata(1d)); nameof(StrokeMiterLimit), typeof(double), typeof(MapOverlay), new PropertyMetadata(1d));
protected override void SetParentMap(MapBase map)
{
if (Foreground == null && map != null)
{
SetBinding(ForegroundProperty,
map.GetBindingExpression(MapBase.ForegroundProperty)?.ParentBinding ??
new Binding { Source = map, Path = new PropertyPath("Foreground") });
}
base.SetParentMap(map);
}
} }
} }

View file

@ -3,7 +3,7 @@
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Documents;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
@ -11,39 +11,50 @@ namespace MapControl
{ {
public partial class MapOverlay public partial class MapOverlay
{ {
public static readonly DependencyProperty FontSizeProperty = Control.FontSizeProperty.AddOwner(typeof(MapOverlay)); public static readonly DependencyProperty FontFamilyProperty = TextElement.FontFamilyProperty.AddOwner(
public static readonly DependencyProperty FontFamilyProperty = Control.FontFamilyProperty.AddOwner(typeof(MapOverlay)); typeof(MapOverlay), new FrameworkPropertyMetadata { Inherits = true, AffectsRender = true });
public static readonly DependencyProperty FontStyleProperty = Control.FontStyleProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty FontStretchProperty = Control.FontStretchProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty FontWeightProperty = Control.FontWeightProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty ForegroundProperty = Control.ForegroundProperty.AddOwner(typeof(MapOverlay));
public static readonly DependencyProperty StrokeProperty = Shape.StrokeProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty FontSizeProperty = TextElement.FontSizeProperty.AddOwner(
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { Inherits = true, AffectsRender = true });
public static readonly DependencyProperty StrokeThicknessProperty = Shape.StrokeThicknessProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty FontStyleProperty = TextElement.FontStyleProperty.AddOwner(
new FrameworkPropertyMetadata(1d, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { Inherits = true, AffectsRender = true });
public static readonly DependencyProperty StrokeDashArrayProperty = Shape.StrokeDashArrayProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty FontStretchProperty = TextElement.FontStretchProperty.AddOwner(
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { Inherits = true, AffectsRender = true });
public static readonly DependencyProperty StrokeDashOffsetProperty = Shape.StrokeDashOffsetProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty FontWeightProperty = TextElement.FontWeightProperty.AddOwner(
new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { Inherits = true, AffectsRender = true });
public static readonly DependencyProperty StrokeDashCapProperty = Shape.StrokeDashCapProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty ForegroundProperty = TextElement.ForegroundProperty.AddOwner(
new FrameworkPropertyMetadata(PenLineCap.Flat, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { Inherits = true, AffectsRender = true, DefaultValue = null });
public static readonly DependencyProperty StrokeStartLineCapProperty = Shape.StrokeStartLineCapProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty StrokeProperty = Shape.StrokeProperty.AddOwner(
new FrameworkPropertyMetadata(PenLineCap.Flat, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true, DefaultValue = null });
public static readonly DependencyProperty StrokeEndLineCapProperty = Shape.StrokeEndLineCapProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty StrokeThicknessProperty = Shape.StrokeThicknessProperty.AddOwner(
new FrameworkPropertyMetadata(PenLineCap.Flat, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeLineJoinProperty = Shape.StrokeLineJoinProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty StrokeDashArrayProperty = Shape.StrokeDashArrayProperty.AddOwner(
new FrameworkPropertyMetadata(PenLineJoin.Miter, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeMiterLimitProperty = Shape.StrokeMiterLimitProperty.AddOwner(typeof(MapOverlay), public static readonly DependencyProperty StrokeDashOffsetProperty = Shape.StrokeDashOffsetProperty.AddOwner(
new FrameworkPropertyMetadata(1d, FrameworkPropertyMetadataOptions.AffectsRender)); typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeDashCapProperty = Shape.StrokeDashCapProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeStartLineCapProperty = Shape.StrokeStartLineCapProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeEndLineCapProperty = Shape.StrokeEndLineCapProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeLineJoinProperty = Shape.StrokeLineJoinProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public static readonly DependencyProperty StrokeMiterLimitProperty = Shape.StrokeMiterLimitProperty.AddOwner(
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true });
public Pen CreatePen() public Pen CreatePen()
{ {