Skip to content

Instantly share code, notes, and snippets.

@ryupold
Last active March 21, 2016 11:56
Show Gist options
  • Save ryupold/2f86f54ad1013c3005d2 to your computer and use it in GitHub Desktop.
Save ryupold/2f86f54ad1013c3005d2 to your computer and use it in GitHub Desktop.
simplifies creation of DependencyProperties (XAML)
public static class PropertyUtils
{
public static DependencyProperty CreateProperty<TProperty, TOwner> (string propertyName, Action<TOwner, TProperty, TProperty> onChange, TProperty defaultValue=default(TProperty)) where TOwner : class
{
return DependencyProperty.Register(propertyName, typeof (TProperty), typeof (TOwner),
new PropertyMetadata(defaultValue, (o, args) =>
{
onChange(o as TOwner, (TProperty)args.OldValue, (TProperty)args.NewValue);
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment