diff --git a/Industrious.Forms/AutoFocusBehavior.cs b/Industrious.Forms/AutoFocusBehavior.cs index 37c0990..9281c5e 100644 --- a/Industrious.Forms/AutoFocusBehavior.cs +++ b/Industrious.Forms/AutoFocusBehavior.cs @@ -13,7 +13,7 @@ namespace Industrious.Forms /// /// <Entry /// Text="{Binding Title}" - /// local:AutoFocusBehavior.When="{Binding ShouldFocusTitle}" /> + /// local:AutoFocusBehavior.FocusWhen="{Binding ShouldFocusTitle}" /> /// /// /// @@ -22,35 +22,37 @@ namespace Industrious.Forms /// /// <Entry /// Text="{Binding Title}" - /// local:AutoFocusBehavior.When="true" /> + /// local:AutoFocusBehavior.FocusWhen="True" /> /// /// public class AutoFocusBehavior : Behavior { - public static readonly BindableProperty WhenProperty = BindableProperty.CreateAttached( - "When", - typeof(bool), + public static readonly BindableProperty FocusWhenProperty = BindableProperty.CreateAttached( + "FocusWhen", + typeof(Boolean), typeof(AutoFocusBehavior), false, - propertyChanged: OnWhenChanged); + propertyChanged: OnFocusWhenChanged); public static Boolean GetFocusWhen(BindableObject bindable) { - var value = (Boolean)bindable.GetValue(WhenProperty); + var value = (Boolean)bindable.GetValue(FocusWhenProperty); return (value); } public static void SetFocusWhen(BindableObject bindable, Boolean value) { - bindable.SetValue(WhenProperty, value); + bindable.SetValue(FocusWhenProperty, value); } - private static void OnWhenChanged(BindableObject bindable, Object oldValue, Object newValue) + private static void OnFocusWhenChanged(BindableObject bindable, Object oldValue, Object newValue) { if ((Boolean)newValue) + { _ = SetFocus((InputView)bindable); + } } diff --git a/README.md b/README.md index e8972ba..99f8877 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,19 @@ Automatically set the input focus to a particular control when a condition becom + forms:AutoFocusBehavior.FocusWhen="{Binding ShouldFocusTitle}" /> ``` +A constant can also be used to always set the input focus when the form is loaded. + +```xml + +``` + ### BooleanBindingExtension A shortcut for binding boolean properties on a Xamarin.Forms view to a non-boolean value on the view model. See [BooleanConverter](#booleanconverter) for info on how values are interpreted. Supports the use of "!" to negate the value.