寻找一点见解。取消选中复选框内的bulletdecorator WPF
我有一个复选框,我已经设置为一种风格,因为我需要使实际的框匹配文本的大小和位置。样式代码如下:
Style TargetType="{x:Type CheckBox}" x:Key="recogCheckbox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="130,4,0,0"/>
<BulletDecorator Name="customBullet" Margin="2,0,0,0" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center">
<TextBlock Width="100" TextWrapping="Wrap" HorizontalAlignment="Left" Foreground="White" Margin="5,0,0,0" Text="Recognition Call"/>
</BulletDecorator>
<ContentPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
的复选框的XAML代码是这样的:
<CheckBox FontFamily="Microsoft Sans Serif" FontSize="12" FontWeight="Bold" Height="20" HorizontalAlignment="Left" HorizontalContentAlignment="Center" Margin="717,193,0,0"
Name="recognitionCheckBox" Style="{StaticResource recogCheckbox}" VerticalAlignment="Top" Width="384" >
</CheckBox>
我想用我的应用程序明确的按钮,以便取消选中该复选框,但是当我通过使用recognitionCheckBox.isChecked = false
引用复选框名称'recognitionCheckBox',它不会取消选中我认为是因为实际框位于我在后面的C#代码中引用时遇到问题的样式中的复选框。
有谁知道一种方法来取消选中样式中的复选框。我一直在寻找几个网站,但没有找到任何帮助我的东西。
我已经尝试了按照您的建议进行绑定。即使尝试手动绑定,而不是模板绑定,但仍无法清除复选框。我可能应该多解释一下。如果我创建的表单上的某个人勾选了复选框,然后决定按下清除表单按钮,它应该清除复选框中的勾号,但它不起作用。 –
将Binding的模式更改为TwoWay,它应该可以工作。我编辑了我的答案。 – mm8
刚刚回到今天工作,并试用它,它完美的作品。将需要记住这一点以供将来使用。非常感谢你。标记为接受的答案。 –