How to work with ToggleSwitch in Windows Phone 7

In this post I will discuss Toggle Switch Button. This comes as part of Silverlight toolkit for Windows Phone 7 and you get it from here

imageimage

To work with Toggle Switch, you need to add namespace


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

 

 

You can use ToggleSwitch as below,

 


<tool:ToggleSwitch x:Name="tglSwitch"
Header="wifi"
Checked="tglSwitch_Checked"
Unchecked="tglSwitch_Unchecked"/>


You can set Header and Content of the Toggleswitch. If you want you can very much templateaize Header and Content.

There are four events attached with Toggle Switch.

image

You can handle events as below,

void tglSwitch_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Its Clicked");

}

void tglSwitch_Indeterminate(object sender, RoutedEventArgs e)
{
MessageBox.Show("Its intermidiate");
}

private void tglSwitch_Checked(object sender, RoutedEventArgs e)
{
tglSwitch.Content = "on";
}

private void tglSwitch_Unchecked(object sender, RoutedEventArgs e)
{
tglSwitch.Content = "off";
}


In this way you can work with ToggleSwitch . I hope this post is useful. Thanks for reading.

Published by

Dhananjay Kumar

Dhananjay Kumar is Developer Evangelist for Infragistics. He is a 8 times Microsoft MVP and well respected Developer Advocate in India.He is the author of 900+ Blog Posts, and can often be found speaking around India at conferences and hosting free workshops for programmers across the country. So far, he has hosted 60 free workshops on various topics like JavaScript, Angular, WCF, ASP.NET MVC, C#, Azure etc. Follow him on twitter @debug_mode for all the updates about his blog posts and workshops. You can send him email at debugmode [at] outlook [dot] com

2 thoughts on “How to work with ToggleSwitch in Windows Phone 7”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s