如何使 CheckBox 看起来像 RadioButton [英] How do I make a CheckBox look like a RadioButton

查看:28
本文介绍了如何使 CheckBox 看起来像 RadioButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 CheckBox,但我希望它具有 RadioButton chrome.

I wanna use a CheckBox but I want it to have the RadioButton chrome.

最简单的方法是什么?

推荐答案

public partial class RadioCheckBox : CheckBox
{...}

RadioCheckBox.xaml:

RadioCheckBox.xaml:

<CheckBox
x:Class="WpfApplication1.RadioCheckBox"
...
xmlns:m="clr-namespace:WpfApplication1"
>
<CheckBox.Style>
    <Style TargetType="{x:Type m:RadioCheckBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type m:RadioCheckBox}">
                    <Grid>
                        <RadioButton
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, 
Path=IsChecked, Mode=TwoWay}"
IsHitTestVisible="False" />
                        <CheckBox
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, 
Path=IsChecked, Mode=TwoWay}" Opacity="0"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</CheckBox.Style>

这篇关于如何使 CheckBox 看起来像 RadioButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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