Introduction
The Telerik Rad Controls for Windows Phone 7 can be obtained from http://www.telerik.com/products/windows-phone.aspx.
The Rad Message Box is used to display output in a nice and enhanced UI.
Question: What is RadListPicker?
In simple terms "It enables user to select a list item from list picker, the items above 5 are displayed in pop mode and below or equals 5 are displayed as per inline mode".
Let's get this implemented practically for a better idea of this!!!
Step 1: The complete code of the IService1.cs looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using PhoneApp2;
namespace WCF_Rad_List_Picker
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
double add(double a, double b);
[OperationContract]
double sub(double a, double b);
[OperationContract]
double mul(double a, double b);
[OperationContract]
double div(double a, double b);
}
}
Step 2: The complete code of the Service1.svc.cs looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using PhoneApp2;
namespace WCF_Rad_List_Picker
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public double add(double a, double b)
{
return a + b;
}
public double sub(double a, double b)
{
return a - b;
}
public double mul(double a, double b)
{
return a * b;
}
public double div(double a, double b)
{
return a / b;
}
}
}
Step 3: The complete code of the Web.Config looks like this:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before
deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid
disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Step 4: The complete code of the MainPage.xaml looks like this:
<phone:PhoneApplicationPage x:Class="Rad_List_Picker_Application.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" FontFamily=
{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="True" xmlns:telerikInput="clr
namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="RadListPicker Application - WCF Service" FontFamily="Verdana" FontSize="22" Style=
{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Windows 7 Phone" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="0,23,0,0" Name="textBlock1" Text="Please Enter First Number: "
FontFamily="Verdana" FontSize="22" VerticalAlignment="Top" />
<TextBlock Height="30" Margin="6,0,0,370" Name="textBlock2" Text="Please Enter Second Number: " FontFamily="Verdana" FontSize="22" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="325,84,0,0" Name="textBox1" VerticalAlignment="Top" Width="131" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="325,0,0,0" Name="textBox2" VerticalAlignment="Top" Width="131" />
<telerikInput:RadListPicker Height="107" HorizontalAlignment="Left" Margin="6,162,0,0" VerticalAlignment="Top" Width="450"
Name="listPicker1" FontFamily="Verdana" FontSize="22" Header="List Picker Options: ">
<telerikInput:RadListPicker.ItemTemplate>
<DataTemplate>
<StackPanel>
<Border BorderBrush="OrangeRed" BorderThickness="3">
<TextBlock Text="{Binding Operation}" FontFamily="Verdana" FontStyle="Italic" Foreground="DeepSkyBlue"></TextBlock>
</Border>
</StackPanel>
</DataTemplate>
</telerikInput:RadListPicker.ItemTemplate>
</telerikInput:RadListPicker>
<Button Content="Addition" FontFamily="Verdana" FontSize="22" Height="72" HorizontalAlignment="Left" Margin="2,332,0,0"
VerticalAlignment="Top" Width="228" Background="Red" x:Name="btnAdd" Click="btnAdd_Click"/>
<Button Content="Subtraction" FontFamily="Verdana" FontSize="22" Height="72" HorizontalAlignment="Left" Margin="230,397,0,0"
VerticalAlignment="Top" Width="232" Background="Green" x:Name="btnSub" Click="btnSub_Click"/>
<Button Content="Multplication" FontFamily="Verdana" FontSize="22" Height="72" HorizontalAlignment="Left" Margin="12,465,0,0"
VerticalAlignment="Top" Width="218" Background="Yellow" x:Name="btnMul" Click="btnMul_Click"/>
<Button Content="Division" FontFamily="Verdana" FontSize="22" Height="72" HorizontalAlignment="Left" Margin="230,529,0,0"
VerticalAlignment="Top" Width="226" Background="Blue" x:Name="btnDiv" Click="btnDiv_Click"/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
Step 5: The complete code of the Arthmetic.cs looks like this:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Rad_List_Picker_Application
{
public class Arthmetic
{
public string Operation
{
get;
set;
}
public double Number1
{
get;
set;
}
public double Number2
{
get;
set;
}
}
}
Step 6: The complete code of the MainPage.xaml.cs looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Rad_List_Picker_Application.ServiceReference1;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Primitives;
using PhoneApp2;
namespace Rad_List_Picker_Application
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void add_Call(object sender, addCompletedEventArgs e)
{
RadMessageBox.Show("Addition Result is: " + e.Result.ToString(),
MessageBoxButtons.OKCancel, "RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
public void btnAdd_Click(object sender, RoutedEventArgs e)
{
List<Arthmetic> arthmeticCollection = new List<Arthmetic>();
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
{
RadMessageBox.Show("Please Enter Some Values", MessageBoxButtons.OKCancel,
"RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
else
{
for (int i = 0; i <= 10; i++)
{
Arthmetic objArthmetic = new Arthmetic();
objArthmetic.Operation = "Addition " + i.ToString(); objArthmetic.Number1 = Convert.ToDouble(textBox1.Text);
objArthmetic.Number2 = Convert.ToDouble(textBox2.Text); arthmeticCollection.Add(objArthmetic);
objClient.addCompleted += new EventHandler<addCompletedEventArgs>(add_Call);
objClient.addAsync(objArthmetic.Number1, objArthmetic.Number2);
}
textBox1.Text = ""; textBox2.Text = "";
}
listPicker1.ItemsSource = arthmeticCollection;
listPicker1.PopupOpenAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 0.2, EndOpacity = 1 };
listPicker1.PopupCloseAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 1, EndOpacity = 0.2 };
}
private void sub_Call(object sender, subCompletedEventArgs e)
{
RadMessageBox.Show("Subtraction Result is: " + e.Result.ToString(), MessageBoxButtons.OKCancel,
"RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
public void btnSub_Click(object sender, RoutedEventArgs e)
{
List<Arthmetic> arthmeticCollection = new List<Arthmetic>();
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
{
RadMessageBox.Show("Please Enter Some Values", MessageBoxButtons.OKCancel,
"RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
else
{
for (int i = 0; i <= 10; i++)
{
Arthmetic objArthmetic = new Arthmetic();
objArthmetic.Operation = "Subtraction " + i.ToString(); objArthmetic.Number1 = Convert.ToDouble(textBox1.Text);
objArthmetic.Number2 = Convert.ToDouble(textBox2.Text);
arthmeticCollection.Add(objArthmetic);
objClient.subCompleted += new EventHandler<subCompletedEventArgs>(sub_Call);
objClient.subAsync(objArthmetic.Number1, objArthmetic.Number2);
}
textBox1.Text = ""; textBox2.Text = "";
}
listPicker1.ItemsSource = arthmeticCollection; listPicker1.PopupOpenAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 0.2, EndOpacity = 1 };
listPicker1.PopupCloseAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 1, EndOpacity = 0.2 };
}
private void mul_Call(object sender, mulCompletedEventArgs e)
{ RadMessageBox.Show("Multiplication Result is: " + e.Result.ToString(),
MessageBoxButtons.OKCancel, "RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
public void btnMul_Click(object sender, RoutedEventArgs e)
{
List<Arthmetic> arthmeticCollection = new List<Arthmetic>();
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
{
RadMessageBox.Show("Please Enter Some Values", MessageBoxButtons.OKCancel,
"RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
else
{
for (int i = 0; i <= 10; i++)
{
Arthmetic objArthmetic = new Arthmetic();
objArthmetic.Operation = "Multiplication " + i.ToString();
objArthmetic.Number1 = Convert.ToDouble(textBox1.Text);
objArthmetic.Number2 = Convert.ToDouble(textBox2.Text);
arthmeticCollection.Add(objArthmetic);
objClient.mulCompleted += new EventHandler<mulCompletedEventArgs>(mul_Call);
objClient.mulAsync(objArthmetic.Number1, objArthmetic.Number2);
}
textBox1.Text = ""; textBox2.Text = "";
}
listPicker1.ItemsSource = arthmeticCollection;
listPicker1.PopupOpenAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 0.2, EndOpacity = 1 };
listPicker1.PopupCloseAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 1, EndOpacity = 0.2 };
}
private void div_Call(object sender, divCompletedEventArgs e)
{
RadMessageBox.Show("Division Result is: " + e.Result.ToString(), MessageBoxButtons.OKCancel,
"RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
public void btnDiv_Click(object sender, RoutedEventArgs e)
{
List<Arthmetic> arthmeticCollection = new List<Arthmetic>();
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
{
RadMessageBox.Show("Please Enter Some Values", MessageBoxButtons.OKCancel,
"RadListPicker - WCF Service", null, false, false,
System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Center, null);
}
else
{
for (int i = 0; i <= 10; i++)
{
Arthmetic objArthmetic = new Arthmetic();
objArthmetic.Operation = "Division " + i.ToString();
objArthmetic.Number1 = Convert.ToDouble(textBox1.Text);
objArthmetic.Number2 = Convert.ToDouble(textBox2.Text);
arthmeticCollection.Add(objArthmetic);
objClient.divCompleted += new EventHandler<divCompletedEventArgs>(div_Call);
objClient.divAsync(objArthmetic.Number1, objArthmetic.Number2);
}
textBox1.Text = ""; textBox2.Text = "";
}
listPicker1.ItemsSource = arthmeticCollection;
listPicker1.PopupOpenAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 0.2, EndOpacity = 1 };
listPicker1.PopupCloseAnimation = new RadFadeAnimation
{
AutoReverse = false, Duration = TimeSpan.FromSeconds(5), StartOpacity = 1, EndOpacity = 0.2 };
}
#region Instance Variables Service1Client objClient = new Service1Client();
#endregion
}
}
Step 7: The output of the application looks like this:
Step 8: The output of the Nothing Entered Application looks like this:
Step 9: The output of the Addition Operation Application looks like this:
Step 10: The output of the List Picked Item Application looks like this:
I hope this article is useful for you. I look forward to your comments and feedback. Thanks Vijay Prativadi