Articles in this section

How to raise SfDataForm label and editor Touch event when data form is read only?

 

If SfDataForm is read only, you cannot interact with the data form label and editor. To raise the Touch event for label and editor, use the OnEditorCreated and GenerateViewForLabel override methods of the DataFormLayoutManager class.

 

 

Employees.cs
 
    public class Employees
    {
        public int EmployeeID { get; set; }
        public string Title { get; set; }
        public decimal ContactID { get; set; }
    }

 

Refer to the following code example for binding DataObject and setting data form as read only.

 

           var linearLayout =new LinearLayout(this);
            var dataform = new SfDataForm(this);
            dataform.DataObject =
               new Employees()
               {
                   ContactID = 1001,
                   EmployeeID = 1709,
                   Title = "Software"
               };
 
            dataform.IsReadOnly = true;
            dataform.LayoutManager = new DataFormLayoutManagerExt(dataform);
            linearLayout.AddView(dataform);
            // Set our view from the "main" layout resource
            SetContentView(linearLayout);

 

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.

 

   public class DataFormLayoutManagerExt : DataFormLayoutManager
    {
        float initialY;
        float currentY;
        bool IsPerformOnTouch;
        public DataFormLayoutManagerExt(SfDataForm dataForm) : base(dataForm)
        {
 
        }
        protected override DataFormItemView CreateDataFormItemView(int rowIndex, int columnIndex)
        {
            var view = base.CreateDataFormItemView(rowIndex, columnIndex);
            return view;
        }
        protected override View GenerateViewForLabel(DataFormItem dataFormItem)
        {
            var view = base.GenerateViewForLabel(dataFormItem);
            view.Touch += OnLabelTouch;
            return view;
        }
 
        // Label/Image click event raised 
        // Event raised three times.  
        private void OnLabelTouch(object sender, View.TouchEventArgs e)
        {
            // Based on condition you can achieve your requirement. 
 
            if (e.Event.Action == MotionEventActions.Down)
            {
                initialY = e.Event.RawY;
                this.IsPerformOnTouch = true;
            }
            else if (e.Event.Action == MotionEventActions.Move)
            {
                currentY = e.Event.RawY;
                // Due to Scrolling operation, we have changed the IsPerform flag is false; 
                if (Math.Abs(currentY - initialY) > 20)
                    this.IsPerformOnTouch = false;
            }
            if (e.Event.Action == MotionEventActions.Up)
            {
                if (IsPerformOnTouch)// Based on the flag, we can do perform here. 
                {
                    // your code here  
                }
            }
        }
 
        protected override void OnEditorCreated(DataFormItem dataFormItem, View editor)
        {
            base.OnEditorCreated(dataFormItem, editor);
            editor.Enabled = true;
            editor.Focusable = false;
            editor.Touch += OnEditorTouch;
        }
 
        // Editor event raised three times.  
        private void OnEditorTouch(object sender, View.TouchEventArgs e)
        {
            // Based on condition you can achieve your requirement. 
 
            if (e.Event.Action == MotionEventActions.Down)
            {
                initialY = e.Event.RawY;
                this.IsPerformOnTouch = true;
            }
            else if (e.Event.Action == MotionEventActions.Move)
            {
                currentY = e.Event.RawY;
                // Due to Scrolling operation, we have changed the IsPerformOnTouch flag is false; 
                if (Math.Abs(currentY - initialY) > 20)
                    this.IsPerformOnTouch = false;
            }
            if (e.Event.Action == MotionEventActions.Up)
            {
                if (IsPerformOnTouch)// Based on the flag, we can do perform here. 
                {
                    // your code here  
                }
            }
        }
    } 
 

 

Note:

The Touch event for label and editor will be raised for every action: touch down, move, and up. So, the label or editor touch event will be raised on the data form scrolling.

 

You can restrict the data form scrolling, up action, and listen the action up only for the editor and label. Based on the scrolling position in move action, the IsPerformOnTouch flag value is set to false. Such that, you can listen the touch action up for the editor and label other than scrolling position.

 

Click here to download the sample.

 

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