RangeSelecter Control In UWP With XAML And C#

Before reading this article, please go through the article links, given below-.

  1. Introduction To Universal Windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015.
  2. How to add UWP ToolKit controls in Universal Application Development With XAML AND C#

     

After reading this article, you can learn, how to use UWP Tool Kit Control - RangeSelecter in Universal Windows apps development with XAML and Visual C#.

The following important tools are required to develop UWP-

  • Windows 10 (Recommended)
  • Visual Studio 2015 Community Edition (It is a free software available online)

Now, we can discuss step by step app development-

Step1 - Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank app -> Give the suitable name for your app (UWPToolkitRangeselector)->OK.

Step 2 - Choose the Target and minimum platform version for your Windows Universal Application will support. Afterwards, the project creates App.xaml and MainPage.xaml. 

UWPToolKit 
 
For adding UWPToolKit control, refer
Step 3 - Add TextBlock control, change the name and text property for the title.
 
UWPTool 

Step 4 - Add Stackpanel control.
 
Stackpanel control. 

Step 5 - Add UWP Tool Kit Name Space in Mainpage.xaml.
,xmlns:Controls="using:Microsoft.Toolkit.Uwp.UI.Controls"

Add RangeSelector control from UWP Tool Kit and change the name property and set the Maximum, RangeMax and RangeMin properties
 
RangeSelector 

Add TextBlock control, change the name and text property for selected minimum range value from RangeSelector.
 
RangeSelector 

Add TextBlock control, change the name and text property for the selected maximum range value from RangeSelector.
 
RangeSelector 

Step 6 - Double click the ValueChanged event in a RangeSelectorcontrol. Automatically, it creates ValueChanged Method in MainPage.xaml.cs.

Step 7 - Add the namespace and the code in the Mainpage.xaml.cs, using Microsoft.Toolkit.Uwp.UI.Controls-
  1. private void RStest_ValueChanged(object sender, RangeChangedEventArgs e)  
  2.   
  3. {  
  4.   
  5.     if (e.ChangedRangeProperty == RangeSelectorProperty.MinimumValue)  
  6.   
  7.     {  
  8.         tblMin.Text = "The Minimum Value is : " + e.NewValue.ToString();  
  9.     } else {  
  10.         tblMax.Text = "The Maximum Value is : " + e.NewValue.ToString();  
  11.     }  
  12.   
  13. }    
  14.  

 RangeSelector

Note - Automatically, the following code will be generated in XAML code view, while we are done in the design view.
  1. Page  
  2.   
  3. xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  4.   
  5. xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"  
  6.   
  7. xmlns: local = "using:UWPToolkitRangeSelector"  
  8.   
  9. xmlns: d = "http://schemas.microsoft.com/expression/blend/2008"  
  10.   
  11. xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"  
  12.   
  13. xmlns: Controls = "using:Microsoft.Toolkit.Uwp.UI.Controls"  
  14.   
  15. x: Class = "UWPToolkitRangeSelector.MainPage"  
  16.   
  17. mc: Ignorable = "d" >  
  18.   
  19.     <  
  20.     Grid Background = "{ThemeResource ApplicationPageBackgroundThemeBrush}" >  
  21.   
  22.     <  
  23.     TextBlock x: Name = "tblTitle"  
  24. HorizontalAlignment = "Left"  
  25. Margin = "62,42,0,0"  
  26. TextWrapping = "Wrap"  
  27. Text = "UWP Tool Kit Range Selector Demo"  
  28. VerticalAlignment = "Top"  
  29. Width = "260"  
  30. FontWeight = "Bold" / >  
  31.   
  32.     <  
  33.     StackPanel x: Name = "SPRange"  
  34. HorizontalAlignment = "Left"  
  35. Height = "166"  
  36. Margin = "62,133,0,0"  
  37. VerticalAlignment = "Top"  
  38. Width = "206" >  
  39.   
  40.     <  
  41.     Controls: RangeSelector x: Name = "RStest"  
  42. FontWeight = "Bold"  
  43. RangeMin = "1"  
  44. RangeMax = "85"  
  45. Maximum = "100"  
  46. ValueChanged = "RStest_ValueChanged" / >  
  47.   
  48.     <  
  49.     TextBlock x: Name = "tblMin"  
  50. TextWrapping = "Wrap"  
  51. Text = ""  
  52. Margin = "0,20,12,0" / >  
  53.   
  54.     <  
  55.     TextBlock x: Name = "tblMax"  
  56. TextWrapping = "Wrap"  
  57. Text = ""  
  58. Margin = "0,25,10,0" / >  
  59.   
  60.     <  
  61.     /StackPanel>  
  62.   
  63. <  
  64. /Grid>  
  65.   
  66. <  
  67. /Page>  
Step 8 - Deploy your app in Local Machine and the output of the UWPToolkitRangeselector app is-

RangeSelector

Summary- 
Now, you have successfully tested UWP Tool Kit - Rangeselector control in Visual C# - UWP environment.