如何使 CheckBox 看起来像 RadioButtonCheckBox、RadioButton

由网友(删除回忆录)分享简介:我想使用 CheckBox,但我希望它具有 RadioButton chrome.I wanna use a CheckBox but I want it to have the RadioButton chrome.最简单的方法是什么?推荐答案public partial class RadioCheckBox...

我想使用 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>

阅读全文

相关推荐

最新文章