I try to handle cases depending on the current value of a toggleSwitch in Blend for Visual Studio 2015 with C#. I want to print the correct value to the debug output.
I have the following code
public sealed partial class MainPage : Page {
public MainPage() {
this.InitializeComponent();
if (toggleSwitch.IsOn == true) {
Debug.WriteLine("On");
}
else {
Debug.WriteLine("Off");
}
}
}
The output prints correctly that the start state of the switch is off. But if I change the value within the UI, the output stays off. No matter how often I change it.
What's the right way to recognize the value change and print it into the output? Help is very appreciated.
private void YourToggleSwitch_Toggled(object sender, RoutedEventArgs e){
if (toggleSwitch.IsOn == true){
Debug.WriteLine("On");
}
else{
Debug.WriteLine("OFF");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.