Dave
Dave

Reputation: 2994

WPF Radio Button IsChecked not working

I have two radio buttons and I want one to be selected by default. I added IsChecked="true" , but it doesn't work. I also tryed to set it in the window load.

But when I click the second option and then click the first option, everything works fine.

It just doesn't show up clicked at first load.

<StackPanel Orientation="Vertical" Margin="0 3 0 0" Height="55">
    <RadioButton IsChecked="True" Padding="1 1 0 10" Name="AutoSaveRadioButton">
        <TextBlock Foreground="Black">Auto Save Test File</TextBlock>
    </RadioButton>
    <RadioButton Margin="0 1 0 0" Padding="1 1 3 1" Name="SaveFileTogetherRadioButton">
        <TextBlock Foreground="Black">Save Test File &amp; <LineBreak /> output file together</TextBlock>
    </RadioButton>
</StackPanel>

Upvotes: 5

Views: 3819

Answers (1)

Richard Deeming
Richard Deeming

Reputation: 31238

Assuming the theme you're using is this one, it looks like a bug with the theme. The Trigger on line 687 only fires when the IsChecked property changes to False, but the initial state of the template is un-checked.

Try changing the trigger to reverse the behaviour:

<Trigger Property="IsChecked" Value="True">
    <Trigger.ExitActions>
        <BeginStoryboard Storyboard="{StaticResource CheckedOff}" />
    </Trigger.ExitActions>
    <Trigger.EnterActions>
        <BeginStoryboard Storyboard="{StaticResource CheckedOn}" />
    </Trigger.EnterActions>
</Trigger>

Upvotes: 4

Related Questions