XAML-Map-Control/MapControl/WinUI/DependencyPropertyHelper.WinUI.cs

52 lines
1.7 KiB
C#
Raw Normal View History

2024-05-21 13:51:10 +02:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
2024-05-21 13:51:10 +02:00
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2024-05-22 11:25:32 +02:00
#if UWP
2024-05-21 13:51:10 +02:00
using Windows.UI.Xaml;
2024-05-22 11:25:32 +02:00
#else
using Microsoft.UI.Xaml;
2024-05-21 13:51:10 +02:00
#endif
2024-05-21 14:39:53 +02:00
2024-05-21 14:06:36 +02:00
#pragma warning disable IDE0060 // Remove unused parameter
2024-05-21 13:51:10 +02:00
namespace MapControl
{
public static class DependencyPropertyHelper
{
public static DependencyProperty RegisterAttached<TValue>(
2024-05-21 13:51:10 +02:00
string name,
Type ownerType,
2024-05-21 13:51:10 +02:00
TValue defaultValue = default,
2024-05-23 19:21:28 +02:00
Action<FrameworkElement, TValue, TValue> changed = null,
bool inherits = false) // unused in WinUI/UWP
2024-05-21 13:51:10 +02:00
{
var metadata = changed == null
? new PropertyMetadata(defaultValue)
: new PropertyMetadata(defaultValue, (o, e) =>
{
if (o is FrameworkElement element)
{
changed(element, (TValue)e.OldValue, (TValue)e.NewValue);
}
});
2024-05-21 13:51:10 +02:00
return DependencyProperty.RegisterAttached(name, typeof(TValue), ownerType, metadata);
}
public static DependencyProperty Register<TOwner, TValue>(
string name,
TValue defaultValue = default,
Action<TOwner, TValue, TValue> changed = null)
where TOwner : DependencyObject
{
var metadata = changed != null
? new PropertyMetadata(defaultValue, (o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue))
: new PropertyMetadata(defaultValue);
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
2024-05-21 13:51:10 +02:00
}
}
}