Articles in this section
Category / Section

How to raise touch event for label and editor in Xamarin.Android DataForm?

1 min read

 

DataForm allows you to raise the Touch event for label and editor.

 

This article explains raising Touch event for label and editor in DataForm using the override methods of the DataFormLayoutManager class.

 

ContactInfo.cs
 
    public class ContactInfo
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Address { get; set; }
    } 

 

Refer to the following code example for binding DataObject.

 

 
           SfDataForm dataForm = new SfDataForm(this);
            dataForm.DataObject = new ContactInfo();
            dataForm.SetBackgroundColor(Color.White);
            SetContentView(dataForm);
 

 

By using the GenerateViewForLabel override method in the DataFormLayoutManager class, you can raise the label’s Touch event. By using the OnEditorCreated override method , you can raise the editor’s Touch event.

 

Refer to the following code example for raising the Touch event for data form label and editor.

 

 
   dataForm.LayoutManager = new DataFormLayoutManagerExt(dataForm,this);
 
    public class DataFormLayoutManagerExt : DataFormLayoutManager
    {
        Context context;
        public DataFormLayoutManagerExt(SfDataForm dataForm, Context _context) : base(dataForm)
        {
            context = _context;
        }
        protected override View GenerateViewForLabel(DataFormItem dataFormItem)
        {
            var label = base.GenerateViewForLabel(dataFormItem);        
            label.Touch += Label_Touch;
            return label;
        }
 
        private void Label_Touch(object sender, View.TouchEventArgs e)
        {
            // your code here
        }
 
        protected override void OnEditorCreated(DataFormItem dataFormItem, View editor)
        {
            base.OnEditorCreated(dataFormItem, editor);
            editor.Touch += Editor_Touch;
        }
 
        private void Editor_Touch(object sender, View.TouchEventArgs e)
        {
           // your code here
        }
    } 

 

To download the sample, click DataFormTouchGesture

 

 

 

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