WPF RadioButton
RadioButton 示例
RadioButton Xaml
<UniformGrid Columns="2"> <RadioButton GroupName="rbRole" Style="{StaticResource RadioButtonLoginRole}" IsChecked="True" Content="主播"/> <RadioButton GroupName="rbRole" Style="{StaticResource RadioButtonLoginRole}" IsChecked="{x:Null}" Content="主持人"/> </UniformGrid>
RadioButton Style
<Style x:Key="RadioButtonLoginRole" TargetType="RadioButton"> <Setter Property="Cursor" Value="Hand"/> <Setter Property="IsChecked" Value="{x:Null}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Foreground" Value="#555"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="RadioButton"> <Border x:Name="border" Height="40" Width="100" BorderThickness="0 0 0 5" BorderBrush="Transparent"> <Grid Background="Transparent"> <TextBlock Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center" /> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter Property="BorderBrush" Value="#FF153F54" TargetName="border"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>