Skip to content

Instantly share code, notes, and snippets.

@JoeM-RP
Created June 24, 2018 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeM-RP/820e1c809eb4783ef49581fe8251bfc4 to your computer and use it in GitHub Desktop.
Save JoeM-RP/820e1c809eb4783ef49581fe8251bfc4 to your computer and use it in GitHub Desktop.
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();
}
}
}
@ivandamyanov
Copy link

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 the this.Completed part of the event to be called only if the control actually has the property NextEntry set. If not, we return.

@JoeM-RP
Copy link
Author

JoeM-RP commented Jul 20, 2020

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