根据您的描述,您应该最多选择三个切换开关之一。
建议使用 Toggled 事件而不是
PointerReleased
事件。判断事件中当前ToggleSwitch是否为IsOn
,然后关闭另外两个ToggleSwitch。
<ToggleSwitch
x:Name="onlineToggleSwitch"
VerticalAlignment="Center"
FlowDirection="LeftToRight"
OffContent=""
OnContent=""
Toggled="onlineToggleSwitch_Toggled">
</ToggleSwitch>
<ToggleSwitch
x:Name="offlineToggleSwitch"
VerticalAlignment="Center"
FlowDirection="LeftToRight"
OffContent=""
OnContent=""
Toggled="offlineToggleSwitch_Toggled">
</ToggleSwitch>
<ToggleSwitch
x:Name="maxToggleSwitch"
VerticalAlignment="Center"
FlowDirection="LeftToRight"
OffContent=""
OnContent=""
Toggled="maxToggleSwitch_Toggled">
</ToggleSwitch>
private void onlineToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (onlineToggleSwitch.IsOn == true)
{
offlineToggleSwitch.IsOn = false;
maxToggleSwitch.IsOn = false;
}
}
private void offlineToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (offlineToggleSwitch.IsOn == true)
{
onlineToggleSwitch.IsOn = false;
maxToggleSwitch.IsOn = false;
}
}
private void maxToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (maxToggleSwitch.IsOn == true)
{
onlineToggleSwitch.IsOn = false;
offlineToggleSwitch.IsOn = false;
}
}