带有按钮样式 XAML 的 RadioButton [英] RadioButton whith Button style XAML

查看:22
本文介绍了带有按钮样式 XAML 的 RadioButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将单选按钮样式更改为 XAML 中的按钮样式?如果选中单选按钮,如何设置背景颜色?我想使用默认颜色(因为我使用不同的皮肤).

How can I change the radiobutton style to a button style in XAML? And how to set the background color if the radiobutton is checked? I would like to use the default colors (because I use differents skins).

推荐答案

需要为 RadioButton 定义 controltemplate,并在 controltemplate 中应用触发器.类似的东西.

You need to define the controltemplate for RadioButton and apply a trigger in controltemplate. Something like.

<Style x:Key="ButtonRadioButtonStyle" TargetType="{x:Type RadioButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RadioButton}">
                    <Button Content="{TemplateBinding Content}"/>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasContent" Value="true">
                            <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
                            <Setter Property="Padding" Value="4,0,0,0"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

并像使用它一样.

<RadioButton Style="{DynamicResource ButtonRadioButtonStyle}">
            <Image Source="ImagePathABC.png"/>
        </RadioButton>

希望对你有帮助..

这篇关于带有按钮样式 XAML 的 RadioButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆