R
R
RubySword2021-07-05 11:43:34
WPF
RubySword, 2021-07-05 11:43:34

WPF Force RadioButton not working how to do?

Good day to all! I make my own style for the radiobutton, but unfortunately the IsChecked trigger does not fire when the value is False, it works when the value is True, and nothing changes when the checkbox is unchecked. The radiobutton consists of two borders - external and internal, internal is hidden. When the checkbox is checked, the internal one is shown. When unchecked, the inner one should hide. And it doesn't work. Here is the code, it is small, please see where my mistake is:

<Style TargetType="RadioButton">
        <Style.Setters>
            <Setter Property="Height" Value="18"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <BulletDecorator Background="White" Cursor="Hand">
                            <BulletDecorator.Bullet>
                                <Grid Height="16" Width="16">
                                    <Border Name="RadioOuter" Background="Transparent" BorderBrush="Gainsboro" 
                                            BorderThickness="2" CornerRadius="2" />
                                    <Border CornerRadius="0" Margin="4" Name="RadioMark" Background="#FFADADAD" 
                                            Visibility="Hidden" />
                                </Grid>
                            </BulletDecorator.Bullet>
                            <TextBlock Text="{TemplateBinding Property=Content}" Margin="5 0 5 0">
                            </TextBlock>
                        </BulletDecorator>
                        <ControlTemplate.Triggers>                           
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="RadioMark" Property="Visibility" Value="Visible"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter TargetName="RadioMark" Property="Visibility" Value="Hidden"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question