I have 3 toggle switches named onlineToggle, offlineToggle, and maxToggle.
XAML:
<ToggleSwitch
x:Name="onlineToggleSwitch"
VerticalAlignment="Center"
FlowDirection="LeftToRight"
OffContent=""
OnContent=""
PointerReleased="onlineToggleSwitch_PointerReleased">
</ToggleSwitch>
<ToggleSwitch
x:Name="offlineToggleSwitch"
VerticalAlignment="Center"
FlowDirection="LeftToRight"
OffContent=""
OnContent=""
PointerReleased="offlineToggleSwitch_PointerReleased">
</ToggleSwitch>
<ToggleSwitch
x:Name="maxToggleSwitch"
VerticalAlignment="Center"
FlowDirection="LeftToRight"
OffContent=""
OnContent=""
PointerReleased="maxToggleSwitch_PointerReleased">
</ToggleSwitch>
I want if onlineToggle isOn = true, then offlineToggle and maxToggle is off. If offlineToggle isOn = true, then onlineToggle and maxToggle are off. And if maxToggle isOn = true, then onlineToggle and offlineToggle are off.
Code:
private void onlineToggleSwitch_PointerReleased(object sender, PointerRoutedEventArgs e)
{
onlineToggleSwitch.IsOn = true;
offlineToggleSwitch.IsOn = false;
maxToggleSwitch.IsOn = false;
}
private async void offlineToggleSwitch_PointerReleased(object sender, PointerRoutedEventArgs e)
{
onlineToggleSwitch.IsOn = false;
offlineToggleSwitch.IsOn = true;
maxToggleSwitch.IsOn = false;
}
private void maxToggleSwitch_PointerReleased(object sender, PointerRoutedEventArgs e)
{
onlineToggleSwitch.IsOn = false;
offlineToggleSwitch.IsOn = false;
maxToggleSwitch.IsOn = true;
}
But I have a problem, namely if onlineToggle isOn = true, then I want to change maxToggle = true, then toogleswitches are all off (maxToggle won't be on) like the video below: https://1drv.ms/v/s!Av6G8Zq_Px8Whi9eSZTSDPqMUCdA?e=25cJtD
How to handle it?
According to your description, you should want to select at most one of the three ToggleSwitchs.
It is recommended to use the Toggled event instead of the
PointerReleasedevent. Determine whether the current ToggleSwitch isIsOnin the event, and then close the other two ToggleSwitchs.