Articles in this section
Category / Section

How to handle events in SfNumericUpDown for Xamarin.iOS platform

2 mins read

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.

        }

    }

}

 

 

 

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