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.

How to handle events in SfRangeSlider of Xamarin.iOS platform

Handling ValueChange and RangeChange event in SfRangeSlider

 

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

 

The below codes explain 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();
            SFRangeSlider slider = new SFRangeSlider();
            slider.Frame = new CoreGraphics.CGRect(1050this.View.Frame.Width-20,400);
            slider.Delegate =new RangeSliderDelegate();
            this.View.AddSubview(slider);


            // Perform any additional setup after loading the view, typically from a nib.
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }
    public class RangeSliderDelegate : SFRangeSliderDelegate
    {
        public override void ValueChange(SFRangeSlider SFRangeSlidernfloat value)
        {
            nfloat Value = value;
            
        }
        public override void RangeValueChange(SFRangeSlider SFRangeSlidernfloat start, nfloat end)
        {
            nfloat RangeStart = start;
            nfloat RangeEnd = end;
        }
    }
}

 

 

 

Step 1:Include the ValueChange and RangeChange 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();
            SFRangeSlider slider = new SFRangeSlider();
            slider.Frame = new CoreGraphics.CGRect(1050this.View.Frame.Width - 20400);

            //RangeSlider ValueChange event
            slider.ValueChange += (sender, e) =>
            {

            };

            //RangeSlider RangeChagne event
            slider.RangeValueChange += (sender, e) =>
            {

            };


            slider.Delegate =new RangeSliderDelegate();

            this.View.AddSubview(slider);


            // Perform any additional setup after loading the view, typically from a nib.
        }

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


    public class RangeSliderDelegate : SFRangeSliderDelegate
    {
        public override void ValueChange(SFRangeSlider SFRangeSlidernfloat value)
        {
            nfloat Value = value;

        }
        public override void RangeValueChange(SFRangeSlider SFRangeSlidernfloat start, nfloat end)
        {
            nfloat RangeStart = start;
            nfloat RangeEnd = end;
        }
    }
}

 

 

 

Step 2: Include the your business logic to new events 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();
            SFRangeSlider slider = new SFRangeSlider();
            slider.Frame = new CoreGraphics.CGRect(1050this.View.Frame.Width - 20400);

            //RangeSlider ValueChange event
            slider.ValueChange += (sender, e) =>
            {
                nfloat Value = e.Value;
            };

            //RangeSlider RangeChagne event
            slider.RangeValueChange += (sender, e) =>
            {
                nfloat RangeStart = e.RangeStart;
                nfloat RangeEnd = e.RangeEnd;
            };



            slider.Delegate =new RangeSliderDelegate();

            this.View.AddSubview(slider);


            // Perform any additional setup after loading the view, typically from a nib.
        }

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


    public class RangeSliderDelegate : SFRangeSliderDelegate
    {
        public override void ValueChange(SFRangeSlider SFRangeSlidernfloat value)
        {
            nfloat Value = value;

        }
        public override void RangeValueChange(SFRangeSlider SFRangeSlidernfloat start, nfloat end)
        {
            nfloat RangeStart = start;
            nfloat RangeEnd = end;
        }
    }

}

 

 

 

 

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();
            SFRangeSlider slider = new SFRangeSlider();
            slider.Frame = new CoreGraphics.CGRect(1050this.View.Frame.Width-20,400);

            //RangeSlider ValueChange event
            slider.ValueChange += (sender, e) => {
                nfloat Value = e.Value;
            };

            //RangeSlider RangeChagne event
            slider.RangeValueChange += (sender, e) =>
            {
                nfloat RangeStart = e.RangeStart;
                nfloat RangeEnd = e.RangeEnd;
            };


            this.View.AddSubview(slider);


            // Perform any additional setup after loading the view, typically from a nib.
        }

        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:
7710 05/09/2017 05/09/2017 Xamarin.Forms SfRangeSlider
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.