所以我只是为了这个例子而简化了这个。我有一个按钮,在它的 ControlTemplate 中有一个红色椭圆。单击按钮时(MouseDown 事件),我希望 Ellipse 动画在 1 秒后变为透明。这是我的xml
<Button>
<Button.Template>
<ControlTemplate>
<Grid Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
ClipToBounds="True">
<Ellipse x:Name="ripple"
Height="20" Width="20"
Fill="Red"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Opacity="1"/>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Button.Template>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseDown">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ripple"
Storyboard.TargetProperty="Opacity"
From="1" To="0" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
问题是当我单击按钮时,椭圆不是透明的。我的猜测是,由于某种原因,它找不到名为“ripple”的对象,但我不知道为什么。我究竟做错了什么?