I have created a simple custom control, and add a simple storyboard to a routed event, I want to do something after the storyboard is completed, but error happens, as below:
CustomControl1.cs codes:
public class CustomControl1 : Control
{
static CustomControl1()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
}
}
Generic.xaml codes:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ControlTemplateEvents">
<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<Viewbox>
<Grid x:Name="TheGrid" Width="100" Height="100" removed="LightBlue">
<Grid.RenderTransform>
<ScaleTransform CenterX="50" CenterY="50" ScaleX="1" ScaleY="1"/>
</Grid.RenderTransform>
</Grid>
</Viewbox>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Control.MouseEnter">
<BeginStoryboard>
<Storyboard Completed="Storyboard_Completed">
<DoubleAnimation Storyboard.TargetName="TheGrid"
Storyboard.TargetProperty="(Grid.RenderTransform).(ScaleTransform.ScaleX)"
From="1" To="1.25" Duration="0:0:.5"/>
<DoubleAnimation Storyboard.TargetName="TheGrid"
Storyboard.TargetProperty="(Grid.RenderTransform).(ScaleTransform.ScaleY)"
From="1" To="1.25" Duration="0:0:.5"/>
<DoubleAnimation Storyboard.TargetName="TheGrid"
Storyboard.TargetProperty="(Grid.RenderTransform).(ScaleTransform.ScaleX)"
From="1.25" To="1" Duration="0:0:.5" BeginTime="0:0:.5"/>
<DoubleAnimation Storyboard.TargetName="TheGrid"
Storyboard.TargetProperty="(Grid.RenderTransform).(ScaleTransform.ScaleY)"
From="1.25" To="1" Duration="0:0:.5" BeginTime="0:0:.5"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Error happens at this line:Storyboard Completed="Storyboard_Completed".
It seems as if I can't add the event like in the other controls(as Button), and the error information is :
'ResourceDictionary' root element requires a x:Class attribute to support event handlers in the XAML file. Either remove the event handler for the Completed event, or add a x:Class attribute to the root element. Line 21 Position 45.
How to deal with this error and get my purpose(do something after the storyboard completed in the procedure code)?
Thanks for your help.