mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
DependencyPropertyHelper
This commit is contained in:
parent
c74c2b1fed
commit
8e82e0bcbd
25 changed files with 224 additions and 176 deletions
|
|
@ -9,6 +9,15 @@ namespace MapControl
|
|||
{
|
||||
public static class DependencyPropertyHelper
|
||||
{
|
||||
public static DependencyProperty Register<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue,
|
||||
FrameworkPropertyMetadataOptions options)
|
||||
where TOwner : DependencyObject
|
||||
{
|
||||
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), new FrameworkPropertyMetadata(defaultValue, options));
|
||||
}
|
||||
|
||||
public static DependencyProperty Register<TOwner, TValue>(
|
||||
string name,
|
||||
TValue defaultValue = default,
|
||||
|
|
@ -64,5 +73,35 @@ namespace MapControl
|
|||
{
|
||||
return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue));
|
||||
}
|
||||
|
||||
public static DependencyProperty AddOwner<TOwner>(
|
||||
DependencyProperty property,
|
||||
FrameworkPropertyMetadataOptions options = FrameworkPropertyMetadataOptions.None)
|
||||
where TOwner : DependencyObject
|
||||
{
|
||||
FrameworkPropertyMetadata metadata = null;
|
||||
|
||||
if (options != FrameworkPropertyMetadataOptions.None)
|
||||
{
|
||||
metadata = new FrameworkPropertyMetadata(property.DefaultMetadata.DefaultValue, options);
|
||||
}
|
||||
|
||||
return property.AddOwner(typeof(TOwner), metadata);
|
||||
}
|
||||
|
||||
public static DependencyProperty AddOwner<TOwner, TValue>(
|
||||
DependencyProperty property,
|
||||
Action<TOwner, TValue, TValue> changed)
|
||||
where TOwner : DependencyObject
|
||||
{
|
||||
FrameworkPropertyMetadata metadata = null;
|
||||
|
||||
if (changed != null)
|
||||
{
|
||||
metadata = new FrameworkPropertyMetadata((o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue));
|
||||
}
|
||||
|
||||
return property.AddOwner(typeof(TOwner), metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue