Stepper in Xamarin Forms

5 views
Skip to first unread message

Sana Rajput

unread,
Nov 3, 2018, 7:22:41 AM11/3/18
to NUnitLite

Hi There, I want to use a Xamarin.Forms stepper to add quantity. I searched a lot but I couldn't find any proper solution for this. I want to customize it like it's buttoned width, color, and most important, I want to insert label between stepper.

If you guys have suggestions for adding quantity for items in xamarin forms, please let me know.

Thanks in Advance

Charlie Poole

unread,
Nov 3, 2018, 4:34:05 PM11/3/18
to nuni...@googlegroups.com
Hi Sana,

This sounds more like a Xamarin Forms question than an NUnitLite question. Someone may have advice here, of course,
but you may also want to ask on one of the Xamarin Forms sites.

Charlie

--
You received this message because you are subscribed to the Google Groups "NUnitLite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nunitlite+...@googlegroups.com.
To post to this group, send email to nuni...@googlegroups.com.
Visit this group at https://groups.google.com/group/nunitlite.
For more options, visit https://groups.google.com/d/optout.

Sana Rajput

unread,
Nov 8, 2018, 1:42:35 AM11/8/18
to NUnitLite
Thank you Charlie, I have seen some Xamarin support related posts in this group so i posted here and also in some other groups so that i can find the solution for my question quickly. Please don't mind.

Raybiztech Ray

unread,
Nov 8, 2018, 2:18:37 AM11/8/18
to NUnitLite

I've used it it works fine for me. Maybe it would help you. If you still need help regarding Xamarin Support feel free to contact me.
Here is the code

In PCL:

public class CustomStepper : StackLayout
    {

        Button PlusBtn;
        Button MinusBtn;
        Entry Entry;

        public static readonly BindableProperty TextProperty =
          BindableProperty.Create(
             propertyName: "Text",
              returnType: typeof(int),
              declaringType: typeof(CustomStepper),
              defaultValue: 1,
              defaultBindingMode: BindingMode.TwoWay);

        public int Text
        {
            get { return (int)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }
        public CustomStepper()
        {
            PlusBtn = new Button { Text = "+", WidthRequest = 40, FontAttributes = FontAttributes.Bold, FontSize = 15 };
            MinusBtn = new Button { Text = "-", WidthRequest = 40, FontAttributes = FontAttributes.Bold, FontSize = 15 };
            switch (Device.RuntimePlatform)
            {

                case Device.UWP:
                case Device.Android:
                    {
                        PlusBtn.BackgroundColor = Color.Transparent;
                        MinusBtn.BackgroundColor = Color.Transparent;
                        break;
                    }
                case Device.iOS:
                    {
                        PlusBtn.BackgroundColor = Color.DarkGray;
                        MinusBtn.BackgroundColor = Color.DarkGray;
                        break;
                    }
            }

            Orientation = StackOrientation.Horizontal;
            PlusBtn.Clicked += PlusBtn_Clicked;
            MinusBtn.Clicked += MinusBtn_Clicked;
            Entry = new Entry { PlaceholderColor = Color.Gray, Keyboard = Keyboard.Numeric, WidthRequest = 40, BackgroundColor = Color.FromHex("#3FFF") ,MaxLength= AppConstantValues.MaxLength.Quantity };
            Entry.Behaviors.Add(new DecimalNumberValidationBehavior());
            Entry.SetBinding(Entry.TextProperty, new Binding(nameof(Text), BindingMode.TwoWay, source: this));
            Entry.TextChanged += Entry_TextChanged;
            Children.Add(PlusBtn);
            Children.Add(Entry);
            Children.Add(MinusBtn);
        }

        private void Entry_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.NewTextValue))
                this.Text = int.Parse(e.NewTextValue);

        }



        private void MinusBtn_Clicked(object sender, EventArgs e)
        {
            if (Text > 1)
                Text--;
        }

        private void PlusBtn_Clicked(object sender, EventArgs e)
        {
            Text++;
        }
    }
Reply all
Reply to author
Forward
0 new messages