WPF RadioButton 样式 (1)

界面

 <RadioButton x:Name="radioButton" IsChecked="True"  Content="界面" HorizontalAlignment="Left" Height="90" Margin="100,334,0,0" VerticalAlignment="Top" Width="60" Style="{DynamicResource RadioButtonOISStyle}"/>
 <RadioButton x:Name="radioButton_Copy"  Content="用户管理" HorizontalAlignment="Right" Height="90" Margin="0,334,100,0" VerticalAlignment="Top" Width="70" Style="{DynamicResource RadioButtonAdminStyle}"/>

样式

        <Style x:Key="RadioButtonOISStyle" TargetType="{x:Type RadioButton}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Background" Value="{StaticResource CheckRadioFillNormal}"/>
            <Setter Property="BorderBrush" Value="{StaticResource CheckRadioStrokeNormal}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Grid Margin="0,0,0,-4.11" Width="60" Height="Auto">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="31*"/>
                                <RowDefinition Height="11*"/>
                            </Grid.RowDefinitions>
                            <!--背景颜色 透明度 边框弧度-->
                            <Rectangle x:Name="rectangle" Fill="{x:Null}" Stroke="{x:Null}" Opacity="1" RadiusX="0" RadiusY="0" StrokeThickness="0" Grid.RowSpan="1"/>
                            <Image x:Name="image" Source="/OIS;component/Resources/Images/oisB.png" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Center" Width="60" Margin="0,4.5" />
                            <!--字体颜色, 字体大小-->
                            <TextBlock x:Name="textBlock" Margin="0" TextWrapping="Wrap" Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Stretch" Height="22" FontSize="16" Foreground="#FFACADAE" Grid.RowSpan="1" Grid.Row="1" Width="33"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="GroupName" Value=""/>
                            <Trigger Property="GroupName" Value=""/>
                            <!--鼠标点击触发器, 背景颜色-->
                            <Trigger Property="IsChecked" Value="True">

                                <Setter Property="Opacity" TargetName="rectangle" Value="1"/>
                                <Setter Property="Source" TargetName="image" Value="/OIS;component/Resources/Images/oisA.png"/>
                                <Setter Property="Foreground" TargetName="textBlock" Value="#FF1AB394"/>
                            </Trigger>

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="RadioButtonAdminStyle" TargetType="{x:Type RadioButton}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Background" Value="{StaticResource CheckRadioFillNormal}"/>
            <Setter Property="BorderBrush" Value="{StaticResource CheckRadioStrokeNormal}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Grid Margin="0,0,0,-4.11" Width="70" Height="Auto">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="31*"/>
                                <RowDefinition Height="11*"/>
                            </Grid.RowDefinitions>
                            <!--背景颜色 透明度 边框弧度-->
                            <Rectangle x:Name="rectangle" Fill="{x:Null}" Stroke="{x:Null}" Opacity="1" RadiusX="0" RadiusY="0" StrokeThickness="0" Grid.RowSpan="1"/>
                            <Image x:Name="image" Source="/OIS;component/Resources/Images/AdminB.png" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Center" Width="60" Margin="0,4.5" />
                            <!--字体颜色, 字体大小-->
                            <TextBlock x:Name="textBlock" Margin="0" TextWrapping="Wrap" Text="{TemplateBinding Content}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="22" FontSize="16" Foreground="#FFACADAE" Grid.RowSpan="1" Grid.Row="1" Width="Auto"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="GroupName" Value=""/>
                            <Trigger Property="GroupName" Value=""/>
                            <!--鼠标点击触发器, 背景颜色-->
                            <Trigger Property="IsChecked" Value="True">

                                <Setter Property="Opacity" TargetName="rectangle" Value="1"/>
                                <Setter Property="Source" TargetName="image" Value="/OIS;component/Resources/Images/adminA.png"/>
                                <Setter Property="Foreground" TargetName="textBlock" Value="#FF1AB394"/>
                            </Trigger>

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小慧哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值