43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
|
using System;
|
|||
|
using Xamarin.Forms;
|
|||
|
|
|||
|
namespace Aurora.Frontend.Behaviors
|
|||
|
{
|
|||
|
public class BehaviorBase<T> : Behavior<T> where T : BindableObject
|
|||
|
{
|
|||
|
public T AssociatedObject { get; private set; }
|
|||
|
|
|||
|
protected override void OnAttachedTo(T bindable)
|
|||
|
{
|
|||
|
base.OnAttachedTo(bindable);
|
|||
|
AssociatedObject = bindable;
|
|||
|
|
|||
|
if (bindable.BindingContext != null)
|
|||
|
{
|
|||
|
BindingContext = bindable.BindingContext;
|
|||
|
}
|
|||
|
|
|||
|
bindable.BindingContextChanged += OnBindingContextChanged;
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnDetachingFrom(T bindable)
|
|||
|
{
|
|||
|
base.OnDetachingFrom(bindable);
|
|||
|
bindable.BindingContextChanged -= OnBindingContextChanged;
|
|||
|
AssociatedObject = null;
|
|||
|
}
|
|||
|
|
|||
|
void OnBindingContextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
OnBindingContextChanged();
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnBindingContextChanged()
|
|||
|
{
|
|||
|
base.OnBindingContextChanged();
|
|||
|
BindingContext = AssociatedObject.BindingContext;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|