Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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