From 3d275cd92455215bd2c67a41ad9eba67792361de Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Sun, 26 May 2024 21:25:36 +0200 Subject: [PATCH] Removed BindingHelper --- MapControl/Avalonia/BindingHelper.Avalonia.cs | 25 ---------------- .../Avalonia/MapControl.Avalonia.csproj | 1 - MapControl/Shared/BindingHelper.cs | 29 ------------------- MapControl/Shared/MapScale.cs | 22 +++++++++++--- MapControl/UWP/MapControl.UWP.csproj | 3 -- MapControl/WinUI/MapContentControl.WinUI.cs | 11 +++++-- MapControl/WinUI/MapGraticule.WinUI.cs | 23 +++++++++++---- MapControl/WinUI/MapItem.WinUI.cs | 11 +++++-- 8 files changed, 51 insertions(+), 74 deletions(-) delete mode 100644 MapControl/Avalonia/BindingHelper.Avalonia.cs delete mode 100644 MapControl/Shared/BindingHelper.cs diff --git a/MapControl/Avalonia/BindingHelper.Avalonia.cs b/MapControl/Avalonia/BindingHelper.Avalonia.cs deleted file mode 100644 index e9d87d45..00000000 --- a/MapControl/Avalonia/BindingHelper.Avalonia.cs +++ /dev/null @@ -1,25 +0,0 @@ -// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control -// Copyright © 2024 Clemens Fischer -// Licensed under the Microsoft Public License (Ms-PL) - -using Avalonia.Data; - -namespace MapControl -{ - internal static class BindingHelper - { - public static Binding CreateBinding(this object source, string property) - { - return new Binding - { - Source = source, - Path = property - }; - } - - public static void SetBinding(this AvaloniaObject target, AvaloniaProperty property, Binding binding) - { - target.Bind(property, binding); - } - } -} diff --git a/MapControl/Avalonia/MapControl.Avalonia.csproj b/MapControl/Avalonia/MapControl.Avalonia.csproj index 4a883d5f..cfda3ddd 100644 --- a/MapControl/Avalonia/MapControl.Avalonia.csproj +++ b/MapControl/Avalonia/MapControl.Avalonia.csproj @@ -23,7 +23,6 @@ - diff --git a/MapControl/Shared/BindingHelper.cs b/MapControl/Shared/BindingHelper.cs deleted file mode 100644 index 9b80b483..00000000 --- a/MapControl/Shared/BindingHelper.cs +++ /dev/null @@ -1,29 +0,0 @@ -// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control -// Copyright © 2024 Clemens Fischer -// Licensed under the Microsoft Public License (Ms-PL) - -#if WPF -using System.Windows; -using System.Windows.Data; -#elif UWP -using Windows.UI.Xaml; -using Windows.UI.Xaml.Data; -#elif WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Data; -#endif - -namespace MapControl -{ - internal static class BindingHelper - { - public static Binding CreateBinding(this FrameworkElement source, string property) - { - return new Binding - { - Source = source, - Path = new PropertyPath(property) - }; - } - } -} diff --git a/MapControl/Shared/MapScale.cs b/MapControl/Shared/MapScale.cs index 3eaf31b1..0ff328a7 100644 --- a/MapControl/Shared/MapScale.cs +++ b/MapControl/Shared/MapScale.cs @@ -7,11 +7,13 @@ using System.Globalization; #if WPF using System.Windows; using System.Windows.Controls; +using System.Windows.Data; using System.Windows.Media; using System.Windows.Shapes; #elif UWP using Windows.Foundation; using Windows.UI.Xaml; +using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Shapes; @@ -19,12 +21,13 @@ using Windows.UI.Xaml.Shapes; using Windows.Foundation; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Shapes; #elif AVALONIA +using Avalonia.Data; using Avalonia.Controls; using Avalonia.Controls.Shapes; -using Avalonia.Media; using DependencyProperty = Avalonia.AvaloniaProperty; using HorizontalAlignment = Avalonia.Layout.HorizontalAlignment; using VerticalAlignment = Avalonia.Layout.VerticalAlignment; @@ -75,11 +78,22 @@ namespace MapControl { base.SetParentMap(map); - line.SetBinding(Shape.StrokeProperty, map.CreateBinding(nameof(Map.Foreground))); - line.SetBinding(Shape.StrokeThicknessProperty, this.CreateBinding(nameof(StrokeThickness))); +#if AVALONIA + line.Bind(Shape.StrokeProperty, + new Binding { Source = map, Path = nameof(MapBase.Foreground) }); + line.Bind(Shape.StrokeThicknessProperty, + new Binding { Source = this, Path = nameof(StrokeThickness) }); +#else + line.SetBinding(Shape.StrokeProperty, + new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) }); + + line.SetBinding(Shape.StrokeThicknessProperty, + new Binding { Source = this, Path = new PropertyPath(nameof(StrokeThickness)) }); +#endif #if UWP || WINUI - label.SetBinding(TextBlock.ForegroundProperty, map.CreateBinding(nameof(Map.Foreground))); + label.SetBinding(TextBlock.ForegroundProperty, + new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) }); #endif } diff --git a/MapControl/UWP/MapControl.UWP.csproj b/MapControl/UWP/MapControl.UWP.csproj index 05a633ee..bfee0381 100644 --- a/MapControl/UWP/MapControl.UWP.csproj +++ b/MapControl/UWP/MapControl.UWP.csproj @@ -50,9 +50,6 @@ AzimuthalProjection.cs - - BindingHelper.cs - BingMapsTileLayer.cs diff --git a/MapControl/WinUI/MapContentControl.WinUI.cs b/MapControl/WinUI/MapContentControl.WinUI.cs index 9b1d1c52..295ecccc 100644 --- a/MapControl/WinUI/MapContentControl.WinUI.cs +++ b/MapControl/WinUI/MapContentControl.WinUI.cs @@ -5,9 +5,11 @@ #if UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Data; #else using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; #endif namespace MapControl @@ -61,15 +63,18 @@ namespace MapControl // if (Background == null) { - SetBinding(BackgroundProperty, parentMap.CreateBinding(nameof(Background))); + SetBinding(BackgroundProperty, + new Binding { Source = parentMap, Path = new PropertyPath(nameof(Background)) }); } if (Foreground == null) { - SetBinding(ForegroundProperty, parentMap.CreateBinding(nameof(Foreground))); + SetBinding(ForegroundProperty, + new Binding { Source = parentMap, Path = new PropertyPath(nameof(Foreground)) }); } if (BorderBrush == null) { - SetBinding(BorderBrushProperty, parentMap.CreateBinding(nameof(Foreground))); + SetBinding(BorderBrushProperty, + new Binding { Source = parentMap, Path = new PropertyPath(nameof(Foreground)) }); } } } diff --git a/MapControl/WinUI/MapGraticule.WinUI.cs b/MapControl/WinUI/MapGraticule.WinUI.cs index f44bac48..36f6fab9 100644 --- a/MapControl/WinUI/MapGraticule.WinUI.cs +++ b/MapControl/WinUI/MapGraticule.WinUI.cs @@ -8,11 +8,13 @@ using System.Linq; #if UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Shapes; #else using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Shapes; #endif @@ -63,7 +65,8 @@ namespace MapControl { if (map != null && Foreground == null) { - SetBinding(ForegroundProperty, map.CreateBinding(nameof(Foreground))); + SetBinding(ForegroundProperty, + new Binding { Source = map, Path = new PropertyPath(nameof(Foreground)) }); } base.SetParentMap(map); @@ -75,8 +78,11 @@ namespace MapControl if (Children.Count == 0) { - path.SetBinding(Shape.StrokeProperty, this.CreateBinding(nameof(Foreground))); - path.SetBinding(Shape.StrokeThicknessProperty, this.CreateBinding(nameof(StrokeThickness))); + path.SetBinding(Shape.StrokeProperty, + new Binding { Source = this, Path = new PropertyPath(nameof(Foreground)) }); + + path.SetBinding(Shape.StrokeThicknessProperty, + new Binding { Source = this, Path = new PropertyPath(nameof(StrokeThickness)) }); Children.Add(path); } @@ -94,12 +100,17 @@ namespace MapControl else { textBlock = new TextBlock { RenderTransform = new MatrixTransform() }; - textBlock.SetBinding(TextBlock.FontSizeProperty, this.CreateBinding(nameof(FontSize))); - textBlock.SetBinding(TextBlock.ForegroundProperty, this.CreateBinding(nameof(Foreground))); + + textBlock.SetBinding(TextBlock.FontSizeProperty, + new Binding { Source = this, Path = new PropertyPath(nameof(FontSize)) }); + + textBlock.SetBinding(TextBlock.ForegroundProperty, + new Binding { Source = this, Path = new PropertyPath(nameof(Foreground)) }); if (FontFamily != null) { - textBlock.SetBinding(TextBlock.FontFamilyProperty, this.CreateBinding(nameof(FontFamily))); + textBlock.SetBinding(TextBlock.FontFamilyProperty, + new Binding { Source = this, Path = new PropertyPath(nameof(FontFamily)) }); } Children.Add(textBlock); diff --git a/MapControl/WinUI/MapItem.WinUI.cs b/MapControl/WinUI/MapItem.WinUI.cs index b7f0f94e..3bc345da 100644 --- a/MapControl/WinUI/MapItem.WinUI.cs +++ b/MapControl/WinUI/MapItem.WinUI.cs @@ -6,10 +6,12 @@ using Windows.System; #if UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; #else using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Input; #endif @@ -53,15 +55,18 @@ namespace MapControl // if (Background == null) { - SetBinding(BackgroundProperty, parentMap.CreateBinding(nameof(Background))); + SetBinding(BackgroundProperty, + new Binding { Source = parentMap, Path = new PropertyPath(nameof(Background)) }); } if (Foreground == null) { - SetBinding(ForegroundProperty, parentMap.CreateBinding(nameof(Foreground))); + SetBinding(ForegroundProperty, + new Binding { Source = parentMap, Path = new PropertyPath(nameof(Foreground)) }); } if (BorderBrush == null) { - SetBinding(BorderBrushProperty, parentMap.CreateBinding(nameof(Foreground))); + SetBinding(BorderBrushProperty, + new Binding { Source = parentMap, Path = new PropertyPath(nameof(Foreground)) }); } } }