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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to handle events in SfNumericUpDown for Xamarin.iOS platform

Handling event in SfNumericUpDown

 

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

 

The below codes explain how to hook the ValueChanged 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();

 

        SFNumericUpDown numericUpDown = new SFNumericUpDown();

        numericUpDown.Frame = new CoreGraphics.CGRect(10, 50, 200, 50);

 

        numericUpDown.NumericUpDownDelegate = new NumericUpDownDelegate();

 

        this.View.AddSubview(numericUpDown);

 

    }

 

    public override void DidReceiveMemoryWarning()

    {

        base.DidReceiveMemoryWarning();

        // Release any cached data, images, etc that aren't in use.

    }

}

 

public class NumericUpDownDelegate : SFNumericUpDownDelegate

{

    public override void ValueChanged(SFNumericUpDown SFNumericUpDown, nfloat 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();

 

        SFNumericUpDown numericUpDown = new SFNumericUpDown();

        numericUpDown.Frame = new CoreGraphics.CGRect(10, 50, 200, 50);

        numericUpDown.ValueChanged += (sender, e) =>

        {

 

        };

 

        numericUpDown.NumericUpDownDelegate = new NumericUpDownDelegate();

 

        this.View.AddSubview(numericUpDown);

 

 

    }

 

    public override void DidReceiveMemoryWarning()

    {

        base.DidReceiveMemoryWarning();

        // Release any cached data, images, etc that aren't in use.

    }

}

 

public class NumericUpDownDelegate : SFNumericUpDownDelegate

{

    public override void ValueChanged(SFNumericUpDown SFNumericUpDown, nfloat value)

    {

        nfloat Value = value;

    }

}

 

}

 

 

 

 

 

Step 2Include 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();

 

        SFNumericUpDown numericUpDown = new SFNumericUpDown();

        numericUpDown.Frame = new CoreGraphics.CGRect(10, 50, 200, 50);

        numericUpDown.ValueChanged += (object sender, ValueEventArgs e) =>

        {

 

        };

 

 

        numericUpDown.NumericUpDownDelegate = new NumericUpDownDelegate();

 

        this.View.AddSubview(numericUpDown);

 

 

    }

 

    public override void DidReceiveMemoryWarning()

    {

        base.DidReceiveMemoryWarning();

        // Release any cached data, images, etc that aren't in use.

    }

}

 

public class NumericUpDownDelegate : SFNumericUpDownDelegate

{

    public override void ValueChanged(SFNumericUpDown SFNumericUpDown, nfloat 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();

 

            SFNumericUpDown numericUpDown = new SFNumericUpDown();

            numericUpDown.Frame = new CoreGraphics.CGRect(10, 50, 200, 50);

            numericUpDown.ValueChanged += (object sender, ValueEventArgs e) =>

            {

                double Value = Convert.ToDouble(e.Value.ToString());

            };

 

 

            this.View.AddSubview(numericUpDown);

 

 

        }

 

        public override void DidReceiveMemoryWarning()

        {

            base.DidReceiveMemoryWarning();

            // Release any cached data, images, etc that aren't in use.

        }

    }

 

 

}

 

 

 

Handling FocusChanged event in SfNumericUpDown:

 

Similarly FocusChanged event has been hooked by EventHandlers. The below codes explain how to hook the FocusChanged event using EventHandlers.

 

 

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();

 

            SFNumericUpDown numericUpDown = new SFNumericUpDown();

            numericUpDown.Frame = new CoreGraphics.CGRect(10, 50, 200, 50);

            numericUpDown.FocusChanged += (object sender, FocusChangedEventArgs e) =>

            {

                numericUpDown.Value = 5;

            };

 

 

            this.View.AddSubview(numericUpDown);

 

        }

 

        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:
8062 11/10/2017 11/10/2017 Xamarin.iOS SfNumericUpDown
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