diff --git a/MapControl/Shared/MapOverlay.cs b/MapControl/Shared/MapOverlay.cs index 2b545dac..339c621e 100644 --- a/MapControl/Shared/MapOverlay.cs +++ b/MapControl/Shared/MapOverlay.cs @@ -110,10 +110,9 @@ namespace MapControl set { SetValue(StrokeMiterLimitProperty, value); } } - protected Binding GetBinding(DependencyProperty property, string propertyName) + protected Binding GetBinding(string propertyName) { - return GetBindingExpression(property)?.ParentBinding ?? - new Binding { Source = this, Path = new PropertyPath(propertyName) }; + return new Binding { Source = this, Path = new PropertyPath(propertyName) }; } } } diff --git a/MapControl/Shared/MapScale.cs b/MapControl/Shared/MapScale.cs index 3ff7f999..11805383 100644 --- a/MapControl/Shared/MapScale.cs +++ b/MapControl/Shared/MapScale.cs @@ -39,10 +39,10 @@ namespace MapControl { MinWidth = 100d; - line.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke))); - line.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness))); + line.SetBinding(Shape.StrokeProperty, GetBinding(nameof(Stroke))); + line.SetBinding(Shape.StrokeThicknessProperty, GetBinding(nameof(StrokeThickness))); #if WINDOWS_UWP - label.SetBinding(TextBlock.ForegroundProperty, GetBinding(ForegroundProperty, nameof(Foreground))); + label.SetBinding(TextBlock.ForegroundProperty, GetBinding(nameof(Foreground))); #endif Children.Add(line); Children.Add(label); diff --git a/MapControl/UWP/MapBase.UWP.cs b/MapControl/UWP/MapBase.UWP.cs index 59d7594b..945f1599 100644 --- a/MapControl/UWP/MapBase.UWP.cs +++ b/MapControl/UWP/MapBase.UWP.cs @@ -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) => diff --git a/MapControl/UWP/MapContentControl.UWP.cs b/MapControl/UWP/MapContentControl.UWP.cs new file mode 100644 index 00000000..ac6469a1 --- /dev/null +++ b/MapControl/UWP/MapContentControl.UWP.cs @@ -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 +{ + /// + /// ContentControl placed on a MapPanel at a geographic location specified by the Location property. + /// + 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); + } + + /// + /// Gets/sets MapPanel.AutoCollapse. + /// + public bool AutoCollapse + { + get { return (bool)GetValue(AutoCollapseProperty); } + set { SetValue(AutoCollapseProperty, value); } + } + + /// + /// Gets/sets MapPanel.Location. + /// + 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)) }); + } + } + } + } + + /// + /// MapContentControl with a Pushpin Style. + /// + public class Pushpin : MapContentControl + { + public Pushpin() + { + DefaultStyleKey = typeof(Pushpin); + } + } +} diff --git a/MapControl/UWP/MapControl.UWP.csproj b/MapControl/UWP/MapControl.UWP.csproj index 056346d9..6897fd43 100644 --- a/MapControl/UWP/MapControl.UWP.csproj +++ b/MapControl/UWP/MapControl.UWP.csproj @@ -195,7 +195,7 @@ - + diff --git a/MapControl/UWP/MapGraticule.UWP.cs b/MapControl/UWP/MapGraticule.UWP.cs index e88fc0ba..90d0919f 100644 --- a/MapControl/UWP/MapGraticule.UWP.cs +++ b/MapControl/UWP/MapGraticule.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); diff --git a/MapControl/UWP/MapOverlay.UWP.cs b/MapControl/UWP/MapOverlay.UWP.cs index 31ab3d02..beaa976a 100644 --- a/MapControl/UWP/MapOverlay.UWP.cs +++ b/MapControl/UWP/MapOverlay.UWP.cs @@ -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))); } } diff --git a/MapControl/UWP/Pushpin.cs b/MapControl/UWP/Pushpin.cs deleted file mode 100644 index d89df02a..00000000 --- a/MapControl/UWP/Pushpin.cs +++ /dev/null @@ -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 -{ - /// - /// Pushpin at a geographic location specified by the Location property. - /// - 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); - } - - /// - /// Gets/sets MapPanel.AutoCollapse. - /// - public bool AutoCollapse - { - get { return (bool)GetValue(AutoCollapseProperty); } - set { SetValue(AutoCollapseProperty, value); } - } - - /// - /// Gets/sets MapPanel.Location. - /// - public Location Location - { - get { return (Location)GetValue(LocationProperty); } - set { SetValue(LocationProperty, value); } - } - } -} diff --git a/MapControl/UWP/Themes/Generic.xaml b/MapControl/UWP/Themes/Generic.xaml index ed1f8306..de66ed1b 100644 --- a/MapControl/UWP/Themes/Generic.xaml +++ b/MapControl/UWP/Themes/Generic.xaml @@ -1,6 +1,8 @@  + - - + - -