We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the text color of the editor in Xamarin.Forms DataForm (SfDataForm)


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 DataFormEditor 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

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile