Skip to content

Commit f279cc2

Browse files
authored
ReadMe file updated.
1 parent 736bcc0 commit f279cc2

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
1-
# manually-focus-dataform-editor-xamarin
2-
How to programmatically set focus to editor in Xamarin.Forms DataForm (SfDataForm)
1+
# How to programmatically set focus to editor in Xamarin.Forms DataForm (SfDataForm)
2+
3+
You can set the focus programmatically to the editor in Xamarin.Forms [SfDataForm](https://help.syncfusion.com/xamarin/dataform/getting-started?) by customizing the existing editor.
4+
5+
Refer to the [online user guide documentation](https://help.syncfusion.com/xamarin/sfdataform/editors?) for creating new custom editor in DataForm.
6+
7+
You can refer the following article.
8+
9+
https://www.syncfusion.com/kb/11311/how-to-programmatically-set-focus-to-editor-in-xamarin-forms-dataform-sfdataform
10+
11+
**C#**
12+
13+
Set focus to view on loading in OnInitializeView method using [Focus](https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.visualelement.focus?view=xamarin-forms) method.
14+
15+
``` c#
16+
public class DataFormTextEditorExt : DataFormTextEditor
17+
{
18+
public DataFormTextEditorExt(SfDataForm dataForm) : base(dataForm)
19+
{
20+
}
21+
protected override void OnInitializeView(DataFormItem dataFormItem, Entry view)
22+
{
23+
base.OnInitializeView(dataFormItem, view);
24+
if (dataFormItem.Name == "Name")
25+
{
26+
view.Focus();
27+
}
28+
}
29+
}
30+
```
31+
**C#**
32+
33+
Set focus to the view automatically at run time by getting the particular editor using [EditorView](https://help.syncfusion.com/cr/xamarin/Syncfusion.SfDataForm.XForms~Syncfusion.XForms.DataForm.DataFormItem~EditorView.html?).
34+
35+
``` c#
36+
private void OnSetFocus(object sender, EventArgs e)
37+
{
38+
var dataFormItem = dataForm.ItemManager.DataFormItems["Name"];
39+
if (dataFormItem != null)
40+
{
41+
if (dataFormItem.TextInputLayout != null)
42+
dataFormItem.TextInputLayout?.InputView?.Focus();
43+
else
44+
dataFormItem.EditorView.Focus();
45+
}
46+
}
47+
```

0 commit comments

Comments
 (0)