Created
April 29, 2019 19:41
-
-
Save Keboo/cc464e09c07b2218baf212fd3a2bc4e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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