问题试图让按钮边框动画上点击 [英] Issue Trying To Get Button Border to Animate on Click

查看:126
本文介绍了问题试图让按钮边框动画上点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态显示按钮的边界,但遇到了麻烦它的工作。这里是XAML我设置:

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">
    <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]

任何想法,为什么?在这个总的小白。我使用Silverlight 4中。

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

推荐答案

的Silverlight只支持一个事件触发加载事件。对于这样的事情,你需要寻找到视觉状态管理。

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

该按钮已经支持了一个名为pressed可视状态。不过,为了改变按钮的视觉行为,你需要先复制它的默认模板,并将其放置在一个静态的资源。

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.

您可以得到用于按钮的此处。让我们假设你给这个 X:。重点的MyButtonStyle

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

您将您的 Col​​orAnimation 添加到现有的故事板为pressed的VisualState

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

那么你的按钮XAML应该是:

Then your button xaml should be:

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

这篇关于问题试图让按钮边框动画上点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆