A few weeks ago we received a support ticket from a customer using RadControls for Windows Phone 7 who wanted to use RadLoopingList to create a control that will allow the end-user to pick numbers in the range 0.00 – 99.99. The requirement was that each decimal position should be represented by a looping list allowing for selection between all digits from 0 to 9. We managed to quickly set up a small WP7 project that demonstrates how this can be done with RadLoopingList and helped our customer in creating a control that looks this way:
Since this scenario could prove useful for many of you, I decided to share it by explaining the steps we took to build this simple control out of already existing components from the RadControls for Windows Phone 7 suite. In another blog post that is yet to come I will extend this behavior by using RadPickerBox and thus creating a RadDate- or RadTimePicker like control for numeric values.
As you can see, the main page contains four RadLoopingList instances that are bound to four different LoopingListDataSource instances providing all the digits in the range 0-9. Between the second and third looping lists there is a text block representing a decimal separator.
The logic behind is quite simple: when the selection in one of the looping lists changes, the selected value is generated by taking the selected digits from all looping lists and composing it accordingly. Additionally, I have modified the styles for the looping list items a bit so that they fit in this scenario and also for better readability.
Let's start with the XAML that builds the page:
"0, 58, 0, 0"
We have a grid panel holding four RadLoopingLists and a TextBlock in the middle that shows the decimal separator. Below the StackPanel that holds the RadLoopingLists I have put a TextBlock that will show the currently selected value in the numeric picker control. Now let's look at the code:
IntegerLoopingListDataSource dataSource =
.loopingList1.DataSource = dataSource;
.loopingList2.DataSource = dataSource;
.loopingList3.DataSource = dataSource;
.loopingList4.DataSource = dataSource;
.txtDecimalSeparator.Text = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;
In the constructor of my page I bind all RadLoopingLists to an instance of the IntegerLoopingListDataSource class (code available just in a second). I also bind to the ScrollCompleted and SelectedIndexChanged events of all looping lists in order to be able to compose the currently selected value (done in the SelectedIndexChanged event by calling the UpdateSelectedValue method), and to collapse all visual items but the selected one to mimic the behavior in the date and time picker controls (done in the ScrollCompleted) event. Here is the code:
sender, Telerik.Windows.Controls.LoopingList.LoopingListScrollEventArgs e)
RadLoopingList typedSender = sender
sender, EventArgs e)
.selectedValue = thousands * 10.0 + hundreds + tens / 10.0 + ones / 100.0;
Here is the code of my special IntegerLoopingListDataSource class:
IntegerLoopingListDataSource : LoopingListDataSource
dataItem.Text = logicalIndex.ToString();
Yes, this is everything you need to do in order to have this neat experience in your WP app. In a further blog post related to this scenario I am also going to demonstrate how to integrate this user control with RadPickerBox and thus create the ultimate number picker control for WP7!
Copyright © 2016, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.