Articles in this section
Category / Section

How to Change Text Color of Editor in Xamarin.Forms DataForm?

1 min read

You can change the default text color of the Text and MultilineText editor in Xamarin.Forms SfDataForm by using custom editor.

You can create and add custom editor to SfDataForm by overriding the  DataFormTextEditor class, where the CustomMultilineTextEditor and CustomTextEditor is inherited using the DataFormMultilineTextEditor and DataFormTextEditor.

Refer to the online user guide documentation for creating new custom editor in DataForm.

C#

Text editor color changed by customizing DataFormTextEditor.

public class CustomTextEditor : DataFormTextEditor
{
    public CustomTextEditor(SfDataForm dataForm) : base(dataForm)
    {
    }
 
    protected override void OnInitializeView(DataFormItem dataFormItem, Entry view)
    {
        base.OnInitializeView(dataFormItem, view);
        dataFormItem.UnfocusedColor = Color.Brown;
        dataFormItem.FocusedColor = Color.DarkGreen;
        view.TextColor = Color.DarkViolet;
    }
}

C#

MultilineText editor color changed by customizing DataFormMultiLineTextEditor.

public class CustomMultilineTextEditor : DataFormMultiLineTextEditor
{
    public CustomMultilineTextEditor( SfDataForm dataForm) :base(dataForm)
    {
    }
    protected override void OnInitializeView(DataFormItem dataFormItem, Editor view)
    {
        base.OnInitializeView(dataFormItem, view);
        dataFormItem.UnfocusedColor = Color.Red;
        dataFormItem.FocusedColor = Color.Blue;
        view.TextColor = Color.DarkOrange;
    }
}

Refer to the following code example for binding DataObject and register the editor using RegisterEditor as CustomTextEditor and CustomMultilineTextEditor to make data form items as custom editor in DataForm.

C#

Customized Text and MultilineText editors registered to DataForm.

namespace DataFormXamarin
{
    public class DataFormBehavior : Behavior<ContentPage>
    {
        SfDataForm dataForm;
        protected override void OnAttachedTo(ContentPage bindable)
        {
            base.OnAttachedTo(bindable);
            dataForm = bindable.FindByName<SfDataForm>("dataForm");
            dataForm.RegisterEditor("MultilineText", new CustomMultilineTextEditor(dataForm));
            dataForm.RegisterEditor("Text", new CustomTextEditor(dataForm));
        }
    }
}

View sample in GitHub


Conclusion

I hope you enjoyed learning about how to Change Text Color of Editor in Xamarin.Forms DataForm .

You can refer to our Xamarin.Forms DataForm page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Forms DataForm Documentation to understand how to manipulate data.

For current customers you can check out on our Winforms components from the License and Download page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Xamarin.Forms DataForm  and other Xamarin.Forms components.

If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied