ToggleButton 切换按钮
切换按钮可以通过使用样式和伪类来呈现布尔值,这些样式和伪类可以存在(true)或不存在(false)。
这允许在每个伪类状态中对控件进行广泛的可能的图形呈现。
更多信息
此示例显示了一个切换按钮,其中包含一个扬声器图标或静音扬声器图标,具体取决于按钮是否具有已检查的伪类。
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Margin="0 5">Audio</TextBlock>
<ToggleButton IsChecked="True">
<Panel>
<PathIcon Classes="audio-on"
Data="{StaticResource speaker_regular}" />
<PathIcon Classes="audio-mute"
Data="{StaticResource speaker_off_regular}" />
</Panel>
</ToggleButton>
</StackPanel>
Styles
<Window.Styles>
<Style Selector="ToggleButton PathIcon.audio-on">
<Setter Property="IsVisible" Value="False"/>
</Style>
<Style Selector="ToggleButton:checked PathIcon.audio-on">
<Setter Property="IsVisible" Value="True"/>
</Style>
<Style Selector="ToggleButton PathIcon.audio-mute">
<Setter Property="IsVisible" Value="True"/>
</Style>
<Style Selector="ToggleButton:checked PathIcon.audio-mute">
<Setter Property="IsVisible" Value="False"/>
</Style>
</Window.Styles>