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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to handle events in SfNumericTextBox for Xamarin.iOS platforms

Handling ValueChangedEvent in SfNumericTextBox

 

In our latest 2017 Volume 2, we have removed Delegate API and SFNumericTextBoxDelegate class from SfNumericTextBox control. Here we have explained how to hook the events using event handler instead of delegates.

 

The below codes explains how to hook the event using delegate class in our old implementation.

 

           

namespace DelegateToEvent
{
    public partial class ViewController : UIViewController
    {
        protected ViewController(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            SFNumericTextBox numericTextBox = new SFNumericTextBox();
            numericTextBox.Frame = new CoreGraphics.CGRect(105020050);
            numericTextBox.NumericTextBoxDelegate = new NumericTextBoxDelegate();
            this.View.AddSubview(numericTextBox);

        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }

    public class NumericTextBoxDelegate : SFNumericTextBoxDelegate
    { 
        public override void ValueChange(SFNumericTextBox SFNumericTextBoxnfloat value)
        {
            nfloat Value = value;
        }
    }

}

 

 

 

Step 1:Include the ValueChanged Event handler as follows.

 

namespace DelegateToEvent
{
    public partial class ViewController : UIViewController
    {
        protected ViewController(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            SFNumericTextBox numericTextBox = new SFNumericTextBox();
            numericTextBox.Frame = new CoreGraphics.CGRect(105020050);

            // NumericTextBox ValueChanged event
            numericTextBox.ValueChanged += (sender, e) =>
            {

            };

            numericTextBox.NumericTextBoxDelegate = new NumericTextBoxDelegate();
            this.View.AddSubview(numericTextBox);

        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }

    public class NumericTextBoxDelegate : SFNumericTextBoxDelegate
    { 
        public override void ValueChange(SFNumericTextBox SFNumericTextBoxnfloat value)
        {
            nfloat Value = value;
        }
    }

}

 

 

 

Step 2: Include the business logics inside the event handler which you have written in delegate class.

 

namespace DelegateToEvent
{
    public partial class ViewController : UIViewController
    {
        protected ViewController(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            SFNumericTextBox numericTextBox = new SFNumericTextBox();
            numericTextBox.Frame = new CoreGraphics.CGRect(105020050);

            // NumericTextBox ValueChanged event
            numericTextBox.ValueChanged += (sender, e) =>
            {
                double Value = Convert.ToDouble(e.Value.ToString());
            };

            numericTextBox.NumericTextBoxDelegate = new NumericTextBoxDelegate();
            this.View.AddSubview(numericTextBox);

        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }

    public class NumericTextBoxDelegate : SFNumericTextBoxDelegate
    { 
        public override void ValueChange(SFNumericTextBox SFNumericTextBoxnfloat value)
        {
            nfloat Value = value;
        }
    }

}

 

 

 

 

 

Step 3: Remove the Delegate API and the Delegate class from the sample.

 


namespace DelegateToEvent
{
    public partial class ViewController : UIViewController
    {
        protected ViewController(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            SFNumericTextBox numericTextBox = new SFNumericTextBox();
            numericTextBox.Frame = new CoreGraphics.CGRect(105020050);

            // NumericTextBox ValueChanged event
            numericTextBox.ValueChanged += (sender, e) =>
            {
                double Value =Convert.ToDouble(e.Value.ToString());
            };

            this.View.AddSubview(numericTextBox);

        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }

}

 

 

 

 

Article ID: Published Date: Last Revised Date: Platform: Control:
7707 05/09/2017 05/09/2017 Xamarin.iOS SfNumericTextBox
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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