开发者

Issue Trying To Get Button Border to Animate on Click

I'm trying to animate the border of a button, but having trouble getting it to work. Here's the XAML I setup:

<Button x:Name="Btn">
    &l开发者_JAVA百科t;Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
            <BeginStoryboard>
                <Storyboard Duration="100" AutoReverse="True"
                            Storyboard.TargetName="Btn"                                     
                            Storyboard.TargetProperty="BorderBrush">
                    <ColorAnimation To="Yellow" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>

I'm getting this error:

Failed to assign to property 'System.Windows.EventTrigger.RoutedEvent'. [Line: 17 Position: 30]

Any idea why? Total noob at this. I'm using Silverlight 4.


Silverlight only supports the Loaded event in an event trigger. For this sort of thing you need to be looking into Visual State Manager.

The Button already supports a Visual State called "Pressed". However in order to change the buttons visual behaviour you need to first copy its default template and place it in a static resource.

You can get a copy of the default style used for button here. Lets assume you give this a x:Key of "MyButtonStyle".

You would add your ColorAnimation to the existing Storyboard for the "Pressed" VisualState.

Then your button xaml should be:

<Button Style="{StaticResource MyButtonStyle}" Content="Click Me" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜