Created
June 24, 2018 20:04
-
-
Save JoeM-RP/820e1c809eb4783ef49581fe8251bfc4 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
using System; | |
using System.Runtime.CompilerServices; | |
using Xamarin.Forms; | |
namespace samples.core.Controls | |
{ | |
public class EntryMoveNextControl : Entry | |
{ | |
public static readonly BindableProperty NextEntryProperty = BindableProperty.Create(nameof(NextEntry), typeof(View), typeof(Entry)); | |
public View NextEntry | |
{ | |
get => (View)GetValue(NextEntryProperty); | |
set => SetValue(NextEntryProperty, value); | |
} | |
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
base.OnPropertyChanged(propertyName); | |
this.Completed += (sender, e) => | |
{ | |
this.OnNext(); | |
}; | |
} | |
public void OnNext() | |
{ | |
NextEntry?.Focus(); | |
} | |
} | |
} |
Yep - OnPropertyChanged
gets called when any property on the page is changed, as far as I'm aware. The above sample was crudely made for a quick blog post I wrote a while back, that has since been made obsolete by the addition of the ReturnType property and the ReturnCommand property in Xamarin.Forms 3.1.
I was young(er) and (more) naive when I wrote this 😃
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot, found it very useful. Is it normal for the
OnPropertyChanged
event to get called one time for each property on each control you have on the page, for instance 4 controls x 4 properties - 16 times? Also, I added a check before thethis.Completed
part of the event to be called only if the control actually has the propertyNextEntry
set. If not, we return.