Skip to content

Commit 53464e1

Browse files
authored
Merge pull request #4 from starkos/fix/autofocus-focuswhenprop
Rename AutoFocusBehavior.When to FocusWhen
2 parents fb14c79 + cc72060 commit 53464e1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Industrious.Forms/AutoFocusBehavior.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Industrious.Forms
1313
/// <code>
1414
/// &lt;Entry
1515
/// Text="{Binding Title}"
16-
/// local:AutoFocusBehavior.When="{Binding ShouldFocusTitle}" /&gt;
16+
/// local:AutoFocusBehavior.FocusWhen="{Binding ShouldFocusTitle}" /&gt;
1717
/// </code>
1818
/// </example>
1919
/// <example>
@@ -22,35 +22,37 @@ namespace Industrious.Forms
2222
/// <code>
2323
/// &lt;Entry
2424
/// Text="{Binding Title}"
25-
/// local:AutoFocusBehavior.When="true" /&gt;
25+
/// local:AutoFocusBehavior.FocusWhen="True" /&gt;
2626
/// </code>
2727
/// </example>
2828
public class AutoFocusBehavior : Behavior<InputView>
2929
{
30-
public static readonly BindableProperty WhenProperty = BindableProperty.CreateAttached(
31-
"When",
32-
typeof(bool),
30+
public static readonly BindableProperty FocusWhenProperty = BindableProperty.CreateAttached(
31+
"FocusWhen",
32+
typeof(Boolean),
3333
typeof(AutoFocusBehavior),
3434
false,
35-
propertyChanged: OnWhenChanged);
35+
propertyChanged: OnFocusWhenChanged);
3636

3737

3838
public static Boolean GetFocusWhen(BindableObject bindable)
3939
{
40-
var value = (Boolean)bindable.GetValue(WhenProperty);
40+
var value = (Boolean)bindable.GetValue(FocusWhenProperty);
4141
return (value);
4242
}
4343

4444
public static void SetFocusWhen(BindableObject bindable, Boolean value)
4545
{
46-
bindable.SetValue(WhenProperty, value);
46+
bindable.SetValue(FocusWhenProperty, value);
4747
}
4848

4949

50-
private static void OnWhenChanged(BindableObject bindable, Object oldValue, Object newValue)
50+
private static void OnFocusWhenChanged(BindableObject bindable, Object oldValue, Object newValue)
5151
{
5252
if ((Boolean)newValue)
53+
{
5354
_ = SetFocus((InputView)bindable);
55+
}
5456
}
5557

5658

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@ Automatically set the input focus to a particular control when a condition becom
3434
<StackLayout>
3535
<Entry
3636
Text="{Binding Title}"
37-
forms:AutoFocusBehavior.When="{Binding ShouldFocusTitle"} />
37+
forms:AutoFocusBehavior.FocusWhen="{Binding ShouldFocusTitle}" />
3838
</StackLayout>
3939
</ContentView>
4040
```
4141

42+
A constant can also be used to always set the input focus when the form is loaded.
43+
44+
```xml
45+
<Entry
46+
Text="{Binding Title}"
47+
forms:AutoFocusBehavior.FocusWhen="True" />
48+
```
49+
4250
### BooleanBindingExtension
4351

4452
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.

0 commit comments

Comments
 (0)