Stepper Control In Xamarin.Forms Application For Android And UWP

Stepper control is a view control that inputs a discrete value, constrained to a range.

Before reading this article, please go through the article How To Create And Use XAML Content Page In Xamarin.Forms Application For Android And Universal Windows Platform.

After reading this article, you will learn how to add Stepper control in Xamarin.Forms Application for Android and Universal Windows Platform with XAML and Visual C# in cross platform application development.

The important tools given below are required to develop UWP.

  1. Windows 10 (Recommended).
  2. Visual Studio 2015 Community Edition (It is a free software available online).
  3. Using Visual Studio 2015 Installer, enable Xamarin (Cross Platform Mobile development and C#/.NET, while installing/modifying Visual Studio 2015.

Now, we can discuss step by step app development.

Step 1

Open Visual Studio 2015 -> Start -> New Project-> Select Cross-Platform (under Visual C#-> Blank app (Xamarin.Forms Portable)-> Give the suitable name for your app (XamFormStepper) ->OK.

Visual studio

Step 2

Now, create project “XamFormStepper_Droid”.

Visual studio

Choose the Target and minimum platform version for your Universal Windows Project.

Visual studio

Create project “XamFormStepper_UWP”.

Visual studio

Step 3

Afterwards, Visual Studio creates 6 projects and displays Getting Started.XamarinPage. Now, we have to update the Xamarin.forms Reference for Portable Project and XamFormStepper_Droid project.

(Please refer How To Create And Use XAML Content Page In Xamarin.Forms Application For Android And Universal Windows Platform)

Step 4

Add a XAML page for Stepper control demo. Right click on XamFormStepper(Portable) project. Select ADD-> NewItem.

Visual studio

Select ->CrossPlatform-> FormXamlPage-> Give the relevant name.

Visual studio

Step 5

Add Stepper tag with items and labels in StepperDemo.Xaml.

  1. <StackLayout Orientation="Vertical">  
  2.     <Label/>  
  3.     <Label Text="Stepper Control in Xamarin.Forms Application - UWP and Android Demo" FontSize="20" VerticalOptions="Center" HorizontalOptions="Center" />  
  4.     <Label/>  
  5.     <Label/>  
  6.     <Label/>  
  7.     <Label x:Name="lbldisp" VerticalOptions="Center" HorizontalOptions="Center"></Label>  
  8.     <Stepper Value="5" Minimum="0" Maximum="10" Increment="0.1" HorizontalOptions="LayoutOptions.Center" VerticalOptions="LayoutOptions.CenterAndExpand" ValueChanged="OnValueChanged" /> </StackLayout>  
Visual studio

Step 6

Add the code, mentioned below in StepperDemo.Xaml.cs.
  1. void OnValueChanged(object sender, ValueChangedEventArgs e) {  
  2.     lbldisp.Text = String.Format("Stepper value is {0:F1}", e.NewValue);  
  3. }  
Visual studio

Step 7

Open (double click) the file App.cs in the Solution Explorer-> XamFormStepper (portable) and set the Root page.

Visual studio

Step 8

We will test Android and UWP. Thus, we can set the Multiple Startup Projects as XamFormStepper.Droid and XamFormStepper.UWP (Universal Windows).

Visual studio

Step 9

Change the Configuration Manager settings, Go to Build -> Configuration Manager, uncheck all the build and deploy options to iOS, Windows, WinPhone, check the Droid and UWP.

Visual studio

Step 10

Deploy your app in a Local Machine and the output of the XamFormStepper app is given below.

Visual studio

After Clicking the +, the output will be, as shown below.

Visual studio

After clicking -, the output will be, as shown below.

Visual studio

Summary

Now, you have successfully created and tested Stepper control in Xamarin.Forms Application for Cross Platform application development, using Visual C# and Xamarin.

 

Up Next
    Ebook Download
    View all
    Learn
    View all