It is necessary that when you press again, the choice was filmed. Help pliz!
I tried it like that, it doesn't click at all ...

private void Profnav_Click(object sender, EventArgs e) { switch (Profnav.IsChecked) { case true: Profnav.IsChecked = false; break; case false: Profnav.IsChecked = true; break; } } 

    1 answer 1

    Well, like this:

     <ToggleButton> <ToggleButton.Template> <ControlTemplate TargetType="ToggleButton"> <Grid> <RadioButton IsChecked="{TemplateBinding IsChecked}" HorizontalAlignment="Center" VerticalAlignment="Center"/> <Border Background="Transparent"/> </Grid> </ControlTemplate> </ToggleButton.Template> </ToggleButton> 

    Explanation: You really want behavior like that of ToggleButton , but to look like a RadioButton . Okay, let's do the ToggleButton , and set the template RadioButton . If you just put RadioButton , then at the click it will always highlight itself, so we put on top transparent in color, but not transparent to Border clicks. Everything.


    If you need a lot of these pieces, determine the style:

     <Window.Resources> <Style TargetType="ToggleButton" x:Key="RadioLookToggleButton"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ToggleButton"> <Grid> <RadioButton IsChecked="{TemplateBinding IsChecked}" HorizontalAlignment="Center" VerticalAlignment="Center"/> <Border Background="Transparent"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> 
     <ToggleButton Style="{StaticResource RadioLookToggleButton}"/> 
    • Yes, that is necessary! Thank! - Awesome7997
    • @ Awesome7997: Please :) - VladD
    • @ Awesome7997: Added HorizontalAlignment and VerticalAlignment to the markup. - VladD