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

48 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
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if WINUI
using Microsoft.UI.Xaml;
#else
using Windows.UI.Xaml;
#endif
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 Register<TOwner, TValue>(
string name,
TValue defaultValue = default,
2024-05-21 14:06:36 +02:00
bool bindTwoWayByDefault = false, // unused in WinUI/UWP
2024-05-21 13:51:10 +02:00
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);
}
public static DependencyProperty RegisterAttached<TOwner, TValue>(
string name,
TValue defaultValue = default,
2024-05-21 14:06:36 +02:00
bool inherits = false, // unused in WinUI/UWP
2024-05-21 13:51:10 +02:00
Action<FrameworkElement, TValue, TValue> changed = null)
where TOwner : DependencyObject
{
var metadata = changed != null
? new PropertyMetadata(defaultValue, (o, e) => changed((FrameworkElement)o, (TValue)e.OldValue, (TValue)e.NewValue))
: new PropertyMetadata(defaultValue);
return DependencyProperty.RegisterAttached(name, typeof(TValue), typeof(TOwner), metadata);
}
}
}
2024-05-21 14:06:36 +02:00
#pragma warning restore IDE0060