Connection Setting Task In Windows Phone 8

Introduction

This article explains how to use the connection setting task in WP8. We will see how to provide shortcuts for various connection settings from within our app to user. For that purpose we will use a Windows Phone task launcher. So let's start.

Connection Setting Task

This is a kind of launcher provided by Windows Phone to launch a connection settings. It helps in maintaining the consistent UI  throughout the platform. It enables the user to adjust its connection related settings.

Before using this task we need to include the following namespace:

using Microsoft.Phone.Tasks;

This task has the connection setting type property that can be set to the following values:

  • WiFi
    For launching WiFi settings.
     
  • Airplane
    For launching airplane settings.
     
  • Cellular
    For launching cellular settings.
     
  • Bluetooth
    For launching Bluetooth settings.
     

By setting this property the selected setting page is opened for the user.

Demo

XAML

<phone:PhoneApplicationPage

    x:Class="Demo.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"

    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation="Portrait"

    shell:SystemTray.IsVisible="True">

 

    <!--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 Text="Demo" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

            <TextBlock  Text="Demo" Margin="9,-7,0,0" FontSize="40" Tap="TextBlock_Tap"/>

        </StackPanel>

 

        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <StackPanel Orientation="Vertical">

                <Button Name="wifiBtn" Click="startBtn_Click" Content="WiFi Settings" HorizontalAlignment="Left" Width="446" Height="129" VerticalAlignment="Bottom"/>

                <Button Name="airplaneBtn" Click="startBtn_Click" Content="AirPlane Settings" HorizontalAlignment="Left"  Width="446" Height="118" VerticalAlignment="Bottom"/>

                <Button Name="btBtn" Click="startBtn_Click" Content="BlueTooth Settings" HorizontalAlignment="Left"  Width="446" Height="118" VerticalAlignment="Bottom"/>

                <Button Name="cellBtn" Click="startBtn_Click" Content="Cellular Settings" HorizontalAlignment="Left"  Width="446" Height="130" VerticalAlignment="Bottom"/>

 

            </StackPanel>

        </Grid>

    </Grid>

</phone:PhoneApplicationPage>

C# Code Behind

using Microsoft.Phone.Controls;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using Windows.Phone.Speech.Synthesis;

using Windows.Devices.Sensors;

using System.Diagnostics;

using Microsoft.Phone.Net.NetworkInformation;

using Microsoft.Phone.Tasks;

 

namespace Demo

{

    public partial class MainPage : PhoneApplicationPage

    {

        // Constructor

        public MainPage()

        {

            InitializeComponent();

        }

        private void startBtn_Click(object sender, RoutedEventArgs e)

        {

            /* Step 1 */  ConnectionSettingsTask cst = new ConnectionSettingsTask();

            /* Step 2 */  cst.ConnectionSettingsType = ConnectionSettingsType.WiFi;

            /* Step 3 */  cst.Show();  

        }

 

        private void cellset(object sender, RoutedEventArgs e)

        {

            /* Step 1 */  ConnectionSettingsTask cst = new ConnectionSettingsTask();

            /* Step 2 */  cst.ConnectionSettingsType = ConnectionSettingsType.Cellular;

            /* Step 3 */  cst.Show();  

        }

 

        private void bt(object sender, RoutedEventArgs e)

        {

            /* Step 1 */  ConnectionSettingsTask cst = new ConnectionSettingsTask();

            /* Step 2 */  cst.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;

            /* Step 3 */  cst.Show();  

        }

 

        private void airplane(object sender, RoutedEventArgs e)

        {

            /* Step 1 */  ConnectionSettingsTask cst = new ConnectionSettingsTask();

            /* Step 2 */  cst.ConnectionSettingsType = ConnectionSettingsType.AirplaneMode;

            /* Step 3 */  cst.Show();  

        }

 

    }

}

The Show method launches the settings.

Output

 


 

 

 


Similar Articles