mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 06:26:41 +00:00
Added PropertyHelper
This commit is contained in:
parent
67e9989327
commit
068a9ef8a6
11 changed files with 76 additions and 61 deletions
|
|
@ -4,12 +4,9 @@
|
|||
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Text;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
|
|
@ -109,10 +106,5 @@ namespace MapControl
|
|||
get { return (double)GetValue(StrokeMiterLimitProperty); }
|
||||
set { SetValue(StrokeMiterLimitProperty, value); }
|
||||
}
|
||||
|
||||
protected Binding GetBinding(string propertyName)
|
||||
{
|
||||
return new Binding { Source = this, Path = new PropertyPath(propertyName) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,10 +39,10 @@ namespace MapControl
|
|||
{
|
||||
MinWidth = 100d;
|
||||
|
||||
line.SetBinding(Shape.StrokeProperty, GetBinding(nameof(Stroke)));
|
||||
line.SetBinding(Shape.StrokeThicknessProperty, GetBinding(nameof(StrokeThickness)));
|
||||
line.SetBinding(Shape.StrokeProperty, this.GetBinding(nameof(Stroke)));
|
||||
line.SetBinding(Shape.StrokeThicknessProperty, this.GetBinding(nameof(StrokeThickness)));
|
||||
#if WINDOWS_UWP
|
||||
label.SetBinding(TextBlock.ForegroundProperty, GetBinding(nameof(Foreground)));
|
||||
label.SetBinding(TextBlock.ForegroundProperty, this.GetBinding(nameof(Foreground)));
|
||||
#endif
|
||||
Children.Add(line);
|
||||
Children.Add(label);
|
||||
|
|
|
|||
32
MapControl/Shared/PropertyHelper.cs
Normal file
32
MapControl/Shared/PropertyHelper.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2021 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Data;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public static class PropertyHelper
|
||||
{
|
||||
public static Binding GetBinding(this object sourceObject, string sourceProperty)
|
||||
{
|
||||
return new Binding { Source = sourceObject, Path = new PropertyPath(sourceProperty) };
|
||||
}
|
||||
|
||||
public static void ValidateProperty(
|
||||
this FrameworkElement targetObject, DependencyProperty targetProperty, object sourceObject, string sourceProperty)
|
||||
{
|
||||
if (targetObject.GetValue(targetProperty) == null &&
|
||||
targetObject.GetBindingExpression(targetProperty) == null)
|
||||
{
|
||||
targetObject.SetBinding(targetProperty, sourceObject.GetBinding(sourceProperty));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue