Access Form Controls at runtime

2 posts, 0 answers
  1. Mark
    Mark avatar
    1 posts
    Member since:
    Dec 2016

    Posted 27 Dec 2016 Link to this post

    Is there a way we can access individual controls in a DataForm at run-time?  I have several individual fields that based on other values need to become read-only etc.

    Also, you do not seem to have a control for a regular button. There is a control for a toggle button, but I need to put some small buttons with icons next to fields to open pop-ups.  i.e. Custom Search forms, or to display additional information about a value that has been entered.

    Finally, your layouts seem to be more inline with phones, and do not take into account tablets.  For example I have a form with several groups of data.  On a phone the groups should be arranged vertically, however, on a tablet in landscape more, there is more than enough space to show the groups across the screen.  How can we achieve this?

    Many thanks for your help.



  2. Rosy Topchiyska
    Rosy Topchiyska avatar
    586 posts

    Posted 29 Dec 2016 Link to this post

    Hello Mark,

    Thank you for contacting us.

    The data form editors in Xamarin Forms are not represented by actual controls (views). You can only access the native editors from the control renderer for each platform. Each renderer has UpdateEditor method where you get the editor instance as a parameter (EntityPropertyEditor for Android and TKDataFormEditor for iOS).

    Adding a custom element in the editor will require platform-specific knowledge. You can find more information about the native controls here:

    You can set different data form layout based on your device size, here you can find information about the layouts. In this thread from the Xamarin forums, I found some information how to get the screen size.

    Here is how to create a custom DataForm renderer on Android get the native editor in the UpdateEditor method:

    public class CustomDataFormRenderer : DataFormRenderer
        protected override void UpdateEditor(Com.Telerik.Widget.Dataform.Visualization.Core.EntityPropertyEditor editor, Telerik.XamarinForms.Input.DataForm.EntityPropertyMetadata metadata)
            base.UpdateEditor(editor, metadata);
            // example for text editor:
            if (typeof(DataFormTextEditor).IsAssignableFrom(editor.GetType()))
                var textEditor = editor.JavaCast<DataFormTextEditor>();
                var textView = textEditor.EditorView.JavaCast<TextView>();
                // modify the editor view here

    And here is how to do the same on iOS:

    public class CustomDataFormRenderer : DataFormRenderer
        protected override void UpdateEditor(TelerikUI.TKDataFormEditor editor, TelerikUI.TKEntityProperty property, Telerik.XamarinForms.Input.DataForm.EntityPropertyMetadata metadata)
            base.UpdateEditor(editor, property, metadata);
            var textEditor = editor as TKDataFormTextFieldEditor;
            if (textEditor != null)
                // modify the text editor here

    Finally, don't forget to replace the default DataFormRenderer type with the custom one in the ExportRenderer attribute.

    I hope this helps. Please, let us know if you have further question.

    Regards, Rosy Topchiyska
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top