List Picker in Windows Phone 8

List Picker

In this part, we are going to see the Windows Phone 8 toolkit controls. First, we will see the most important control List picker. Write the below xaml code in your MainPage.xaml.

<Grid x:Name="ContentPanel" Margin="10,138,14,23" Grid.RowSpan="2">

  <toolkit:ListPicker x:Name="Listpickername" Margin="37,42,149,430" ExpansionMode="ExpansionAllowed" Background="#FFF7EBEB">

  </toolkit:ListPicker>

  <toolkit:ListPicker x:Name="Listpicker2" Margin="37,182,149,358" ExpansionMode="FullScreenOnly" SelectionMode="Multiple" Background="#FFF7EBEB"/>

  <toolkit:DatePicker x:Name="Datepickername" Margin="10,249,294,289"></toolkit:DatePicker>

  <toolkit:TimePicker x:Name="Timepickername" Margin="176,249,128,288"></toolkit:TimePicker>

  <toolkit:ToggleSwitch x:Name="Togglename" Click="Togglename_Click_1" IsChecked="true" Margin="27,324,210,171" SwitchForeground="#FFF1220E"></toolkit:ToggleSwitch>

</Grid>

Add the below XAML namespace in your "MainPage.xaml"

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

Now your design looks like below screen.



Next add items to list picker using below code.

C# Code
 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Navigation;

using Microsoft.Phone.Controls;

using Microsoft.Phone.Shell;

using Wph8ToolkitDemo.Resources;

 

namespace Wph8ToolkitDemo

{

    public partial class MainPage : PhoneApplicationPage

    {

        public MainPage()

        {

            InitializeComponent();

            Listpickername.Items.Add("Item1");

            Listpickername.Items.Add("Item2");

 

            Listpicker2.Items.Add("List1");

            Listpicker2.Items.Add("List2");

            Listpicker2.Items.Add("List3");

        }

        private void Togglename_Click_1(object sender, RoutedEventArgs e)

        {

            if (Togglename.IsChecked == true)

                MessageBox.Show("Switch is on");

            else

                MessageBox.Show("Switch is of");

        }

    }

}

Run your app and see the output as shown below.

 
Ebook Download
View all
Learn
View all