Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind Checked event for radio button in WPF?

I am using the following markup in WPF:

    <StackPanel.Triggers>
        <EventTrigger RoutedEvent="RadioButton.Checked" SourceName="xmlRadioButton">
            <EventTrigger.Actions>
                <BeginStoryboard Storyboard="{StaticResource ShowXmlPanel}"/>
            </EventTrigger.Actions>
        </EventTrigger>
        <EventTrigger RoutedEvent="RadioButton.Checked" SourceName="adiRadioButton">
            <EventTrigger.Actions>
                <BeginStoryboard Storyboard="{StaticResource ShowAdiPanel}"/>
            </EventTrigger.Actions>
        </EventTrigger>
    </StackPanel.Triggers>

Though this works fine when I run the code, I get the following error in the designer window of VS 2008:

Value 'RadioButton.Checked' cannot be assigned to property 'RoutedEvent'. Invalid event name.

Any idea why, and how can I fix this?

like image 607
nullDev Avatar asked Mar 30 '10 06:03

nullDev


1 Answers

RadioButton is a ToggleButton. The designer does support the attached ToggleButton properties, but not the RadioButton ones (except in a RadioButton tag of course).

You need to use the class name that defines the property/event for the designer to accept it (thought there is no difference at runtime, since RadioButton IS a ToggleButton as I said, but the designer is not a real compiler).

So in your case, use <EventTrigger RoutedEvent="ToggleButton.Checked ..." ;-)

like image 196
Aurelien Ribon Avatar answered Oct 20 '22 18:10

Aurelien Ribon