所以我试图在悬停时放大图像,所以我在网上查看了一些示例,它可以处理单个图像,但是我希望它可以处理多个图像,这些是代码我在网上发现它可以使用单个图像(由Jeff Yates提供解决方案)
的Xaml:
<Grid.Resources>
<Storyboard x:Name="growStoryboard">
<DoubleAnimation
Storyboard.TargetProperty="Width"
Storyboard.TargetName="testButton"
Duration="0:0:0.1"
By="20">
</DoubleAnimation>
<DoubleAnimation
Storyboard.TargetProperty="Height"
Storyboard.TargetName="testButton"
Duration="0:0:1"
By="-20">
</DoubleAnimation>
</Storyboard>
<Storyboard x:Name="shrinkStoryboard">
<DoubleAnimation
Storyboard.TargetProperty="Width"
Storyboard.TargetName="testButton"
Duration="0:0:1"
By="-20">
</DoubleAnimation>
<DoubleAnimation
Storyboard.TargetProperty="Height"
Storyboard.TargetName="testButton"
Duration="0:0:0.1"
By="20">
</DoubleAnimation>
</Storyboard>
</Grid.Resources>
<Button x:Name="testButton" Content="Test" Grid.Column="1" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave" VerticalAlignment="Center" HorizontalAlignment="Center" Width="50" Height="50">
</Button>
</Grid>
</UserControl>
代码隐藏:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
this.shrinkStoryboard.SkipToFill();
this.growStoryboard.Begin();
}
private void Button_MouseLeave(object sender, MouseEventArgs e)
{
this.growStoryboard.SkipToFill();
this.shrinkStoryboard.Begin();
}
}
答案 0 :(得分:1)
我会在ScaleTransform上使用动画来执行此操作:
<Storyboard x:Key="MouseOverRectangleStoryBoard">
<DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1" From="1" To="1.1"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(ScaleTransform.ScaleX)">
</DoubleAnimation>
<DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1" From="1" To="1.1"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(ScaleTransform.ScaleY)">
</DoubleAnimation>
</Storyboard>
<Storyboard x:Key="MouseLeaveRectangleStoryBoard">
<DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1" From="1.1" To="1"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(ScaleTransform.ScaleX)">
</DoubleAnimation>
<DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1" From="1.1" To="1"
Storyboard.TargetProperty="(Rectangle.RenderTransform).(ScaleTransform.ScaleY)">
</DoubleAnimation>
</Storyboard>
代码用于矩形,但它完全相同。