Skip to content

Instantly share code, notes, and snippets.

@Keboo
Created April 29, 2019 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keboo/cc464e09c07b2218baf212fd3a2bc4e6 to your computer and use it in GitHub Desktop.
Save Keboo/cc464e09c07b2218baf212fd3a2bc4e6 to your computer and use it in GitHub Desktop.
public abstract class BindableBehavior<T> : Behavior<T> where T : BindableObject
{
protected override void OnAttachedTo(T bindable)
{
if (bindable != null)
{
this.InheritsBindingContextFrom(bindable);
}
base.OnAttachedTo(bindable);
}
}
public static class BindableObjectMixins
{
public static void InheritsBindingContextFrom(this BindableObject target, BindableObject source)
{
if (target == null) throw new ArgumentNullException(nameof(target));
if (source == null) throw new ArgumentNullException(nameof(source));
source.BindingContextChanged += OnBindingContextChanged;
BindableObject.SetInheritedBindingContext(target, source.BindingContext);
void OnBindingContextChanged(object sender, EventArgs e)
{
BindableObject.SetInheritedBindingContext(target, source.BindingContext);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment