本文介绍了如何使一个CheckBox看起来像一个RadioButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是最简单的方法是什么?
我想使用一个复选框, div class =h2_lin>解决方案
这是最简单的方法是什么?
我想使用一个复选框, div class =h2_lin>解决方案
public partial class RadioCheckBox:CheckBox
{...}
RadioCheckBox.xaml:
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>
I wanna use a CheckBox but I want it to have the RadioButton chrome.
What's the easiest way to do this?
public partial class RadioCheckBox : CheckBox
{...}
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!