小编Dav*_*hen的帖子

WPF - 单选按钮控件模板绑定"IsChecked"不起作用

我有一个如下控件模板,我想IsChecked在用户选择单选按钮时获取属性.

但是当用户选择单选按钮"A"时,它的IsChecked属性仍然显示为false.为什么?

<ControlTemplate x:Key="RadioBtnTemplate" TargetType="{x:Type RadioButton}">
   <Grid>
     <StackPanel Margin="5">
         <RadioButton Name="tempbtn" IsChecked="{TemplateBinding IsChecked}" FontFamily="Segoe UI" FontSize="18.667" Content="{TemplateBinding Content}" GroupName="{TemplateBinding GroupName}"/>
      </StackPanel>
    </Grid>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

我使用这个模板:

<RadioButton GroupName="CG" x:Name="_rdoBtnA" Content="A" Template="{DynamicResource RadioBtnTemplate}" IsChecked="True"/>
<RadioButton GroupName="CG" x:Name="_rdoBtnB" Content="B" Template="{DynamicResource RadioBtnTemplate}" />
<RadioButton GroupName="CG" x:Name="_rdoBtnC" Content="C" Template="{DynamicResource RadioBtnTemplate}" />
Run Code Online (Sandbox Code Playgroud)

wpf xaml controltemplate ischecked

5
推荐指数
1
解决办法
2902
查看次数

标签 统计

controltemplate ×1

ischecked ×1

wpf ×1

xaml ×1