WPF简单动画
CSDN上有人问,怎么用WPF实现一个包含Image控件的Grid容器,在鼠标移入Image控件的时候,改变Grid的高度,而当鼠标移出Image的时候,Grid的高度恢复。例子代码如下:<Window x:Class="WpfApplication1.MainW
·
CSDN上有人问,怎么用WPF实现一个包含Image控件的Grid容器,在鼠标移入Image控件的时候,改变Grid的高度,而当鼠标移出Image的时候,Grid的高度恢复。
例子代码如下:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid Height="200" HorizontalAlignment="Left" Margin="79,60,0,0" Background="Green" x:Name="grid1" VerticalAlignment="Top" Width="400">
<Image Height="150" HorizontalAlignment="Left" Margin="83,16,0,0" x:Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="/WpfApplication1;component/Images/azsy.png">
<Image.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid1" Storyboard.TargetProperty="Height" From="200" To="250" Duration="0:0:5"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid1" Storyboard.TargetProperty="Height" From="250" To="200" Duration="0:0:5"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
</Image>
</Grid>
</Grid>
</Window>
更多推荐
已为社区贡献3条内容
所有评论(0)