开发者

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>
        <开发者_JAVA技巧/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?


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 ..." ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜