-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from Insire/dev
update from dev
- Loading branch information
Showing
32 changed files
with
491 additions
and
230 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
48 changes: 48 additions & 0 deletions
48
src/MvvmScarletToolkit.Xamarin.Forms/Behaviors/BehaviorBase.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using Xamarin.Forms; | ||
|
||
namespace MvvmScarletToolkit | ||
{ | ||
/// <summary> | ||
/// base class providing the currently associated control that also forwwards updates to the bindingcontext as it changes on the control | ||
/// </summary> | ||
/// <typeparam name="T">a control</typeparam> | ||
public abstract class BehaviorBase<T> : Behavior<T> | ||
where T : BindableObject | ||
{ | ||
protected 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; | ||
} | ||
|
||
private void OnBindingContextChanged(object sender, EventArgs e) | ||
{ | ||
OnBindingContextChanged(); | ||
} | ||
|
||
protected override void OnBindingContextChanged() | ||
{ | ||
base.OnBindingContextChanged(); | ||
|
||
BindingContext = AssociatedObject?.BindingContext; | ||
} | ||
} | ||
} |
Oops, something went wrong.