This is a migrated thread and some comments may be shown as answers.

Access Form Controls at runtime

1 Answer 153 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 27 Dec 2016, 09:37 AM

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 29 Dec 2016, 04:37 PM

Hello Mark,

Thank you for contacting us.

The data 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
Tags
DataForm
Asked by
Mark
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Share this question
or