日期:2014-05-18 浏览次数:21282 次
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:StoryboardTest"> <Style TargetType="{x:Type local:CustomControl1}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:CustomControl1}"> <Viewbox> <Grid Background="LightBlue" x:Name="theGrid"> <Rectangle x:Name="faceRect" Width="50" Height="50" > <Rectangle.RenderTransform> <ScaleTransform CenterX="25" CenterY="25" ScaleX="1" ScaleY="1"/> </Rectangle.RenderTransform> </Rectangle> </Grid> </Viewbox> <ControlTemplate.Triggers> <EventTrigger RoutedEvent="Rectangle.MouseEnter" SourceName="faceRect"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="faceRect" Storyboard.TargetProperty="Width" To="100"/> <DoubleAnimation Storyboard.TargetName="faceRect" Storyboard.TargetProperty="Height" To="100"/> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="Rectangle.MouseLeave" SourceName="faceRect"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="faceRect" Storyboard.TargetProperty="Width" To="50"/> <DoubleAnimation Storyboard.TargetName="faceRect" Storyboard.TargetProperty="Height" To="50"/> </Storyboard> </BeginStoryboard> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>