mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 22:18:56 +00:00
Added DependencyPropertyHelper
This commit is contained in:
parent
422f1dce0d
commit
3706709cfc
22 changed files with 967 additions and 1879 deletions
47
MapControl/Avalonia/DependencyPropertyHelper.Avalonia.cs
Normal file
47
MapControl/Avalonia/DependencyPropertyHelper.Avalonia.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
using Avalonia.Controls;
|
||||
using System;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1001")]
|
||||
public static class DependencyPropertyHelper
|
||||
{
|
||||
public static AvaloniaProperty Register<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue = default,
|
||||
bool bindTwoWayByDefault = false,
|
||||
Action<TOwner, TValue, TValue> propertyChanged = null)
|
||||
where TOwner : AvaloniaObject
|
||||
{
|
||||
StyledProperty<TValue> property = AvaloniaProperty.Register<TOwner, TValue>(name, defaultValue, false,
|
||||
bindTwoWayByDefault ? Avalonia.Data.BindingMode.TwoWay : Avalonia.Data.BindingMode.OneWay);
|
||||
|
||||
if (propertyChanged != null)
|
||||
{
|
||||
property.Changed.AddClassHandler<TOwner, TValue>(
|
||||
(o, e) => propertyChanged(o, e.OldValue.Value, e.NewValue.Value));
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
public static AvaloniaProperty RegisterAttached<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue = default,
|
||||
bool inherits = false,
|
||||
Action<Control, TValue, TValue> propertyChanged = null)
|
||||
where TOwner : AvaloniaObject
|
||||
{
|
||||
AttachedProperty<TValue> property = AvaloniaProperty.RegisterAttached<TOwner, Control, TValue>(name, defaultValue, inherits);
|
||||
|
||||
if (propertyChanged != null)
|
||||
{
|
||||
property.Changed.AddClassHandler<Control, TValue>(
|
||||
(o, e) => propertyChanged(o, e.OldValue.Value, e.NewValue.Value));
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue