2024-05-20 23:24:34 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
|
|
|
|
// Copyright © 2024 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class DependencyPropertyHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static DependencyProperty Register<TOwner, TValue>(
|
|
|
|
|
|
string name,
|
|
|
|
|
|
TValue defaultValue = default,
|
|
|
|
|
|
bool bindTwoWayByDefault = false,
|
2024-05-21 13:51:10 +02:00
|
|
|
|
Action<TOwner, TValue, TValue> changed = null,
|
|
|
|
|
|
Func<TOwner, TValue, TValue> coerce = null)
|
2024-05-20 23:24:34 +02:00
|
|
|
|
where TOwner : DependencyObject
|
|
|
|
|
|
{
|
|
|
|
|
|
var metadata = new FrameworkPropertyMetadata
|
|
|
|
|
|
{
|
|
|
|
|
|
DefaultValue = defaultValue,
|
|
|
|
|
|
BindsTwoWayByDefault = bindTwoWayByDefault
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-21 13:51:10 +02:00
|
|
|
|
if (changed != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
metadata.PropertyChangedCallback = (o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (coerce != null)
|
2024-05-20 23:24:34 +02:00
|
|
|
|
{
|
2024-05-21 13:51:10 +02:00
|
|
|
|
metadata.CoerceValueCallback = (o, v) => coerce((TOwner)o, (TValue)v);
|
2024-05-20 23:24:34 +02:00
|
|
|
|
}
|
2024-05-21 13:51:10 +02:00
|
|
|
|
|
2024-05-20 23:24:34 +02:00
|
|
|
|
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static DependencyProperty RegisterAttached<TOwner, TValue>(
|
|
|
|
|
|
string name,
|
|
|
|
|
|
TValue defaultValue = default,
|
|
|
|
|
|
bool inherits = false,
|
2024-05-21 13:51:10 +02:00
|
|
|
|
Action<FrameworkElement, TValue, TValue> changed = null)
|
2024-05-20 23:24:34 +02:00
|
|
|
|
where TOwner : DependencyObject
|
|
|
|
|
|
{
|
|
|
|
|
|
var metadata = new FrameworkPropertyMetadata
|
|
|
|
|
|
{
|
|
|
|
|
|
DefaultValue = defaultValue,
|
|
|
|
|
|
Inherits = inherits
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-21 13:51:10 +02:00
|
|
|
|
if (changed != null)
|
2024-05-20 23:24:34 +02:00
|
|
|
|
{
|
2024-05-21 13:51:10 +02:00
|
|
|
|
metadata.PropertyChangedCallback = (o, e) => changed((FrameworkElement)o, (TValue)e.OldValue, (TValue)e.NewValue);
|
2024-05-20 23:24:34 +02:00
|
|
|
|
}
|
2024-05-21 13:51:10 +02:00
|
|
|
|
|
2024-05-20 23:24:34 +02:00
|
|
|
|
return DependencyProperty.RegisterAttached(name, typeof(TValue), typeof(TOwner), metadata);
|
|
|
|
|
|
}
|
2024-05-21 13:51:10 +02:00
|
|
|
|
|
|
|
|
|
|
public static DependencyPropertyKey RegisterReadOnly<TOwner, TValue>(
|
|
|
|
|
|
string name,
|
|
|
|
|
|
TValue defaultValue = default)
|
|
|
|
|
|
where TOwner : DependencyObject
|
|
|
|
|
|
{
|
|
|
|
|
|
return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue));
|
|
|
|
|
|
}
|
2024-05-20 23:24:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|