Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Toggle Switch Control For Windows 10
WhatsApp
Ramees
5y
54k
0
2
100
Article
Introduction
Toggle Switch represents a switch that can be toggled between two states. We can use a Toggle Switch control to let the user switch an option between on and off states. We use the Ison property to determine the state of the switch. Handle the Toggled event to respond to changes in the state.
Step 1
Open a blank app and add a ToggleSwitch control either from the toolbox or by copying the following XAML code into your grid.
<
TextBlock
Text
=
"Toggle Switch"
FontSize
=
"20"
>
</
TextBlock
>
<
StackPanel
Margin
=
"10,40,0,0"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
ToggleSwitch
Name
=
"myToggleSwitch"
Header
=
"Toggle Switch"
OffContent
=
"OFF"
OnContent
=
"ON"
Toggled
=
"myToggleSwitch_Toggled"
/>
<
ProgressRing
Name
=
"myRing"
Height
=
"40"
Width
=
"40"
/>
</
StackPanel
>
</
StackPanel
>
Here we have added a ToggleSwitch and a ProgressRing. By toggling the switch we are controlling the IsActive property of the Progress Ring.
Step 2
Copy and paste the following code to the cs page to handle the events generated on Toggling:
private void myToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (myToggleSwitch.IsOn)
{
myRing.IsActive
=
true
;
}
else
{
myRing.IsActive
=
false
;
}
}
Step 3
Run your application and test yourself.
Summary
In this article, we learned about Toggle Switch Control For Windows 10.
Toggle Switch Control
Toggle Switch Control in Windows 10
UWP
Windows 10
Up Next
Ebook Download
View all
Printing in C# Made Easy
Read by 22.4k people
Download Now!
Learn
View all
Membership not found