[英]DoubleAnimation for image with Storyboard.TargetProperty=“Height”
我已经阅读了如何通过WPF动画使图像尺寸增大(赋予选择的错觉)? 并尝试使用DoubleAnimation
更改图像的高度,但是它不起作用。
<Image Name="image" Height="100" Source="http://www.online-image-editor.com/styles/2013/images/example_image.png" Stretch="None">
<Image.Resources>
<Storyboard x:Name="show">
<DoubleAnimation
Storyboard.TargetName="image"
Storyboard.TargetProperty="Height"
From="100" To="400" Duration="0:0:1"
/>
</Storyboard>
</Image.Resources>
</Image>
<Button Content="image stretch" Click="button_clicked" />
这是button_clicked
函数:
private void button_clicked(object sender, RoutedEventArgs e)
{
show.Begin();
}
[edit]:因为Johan Falk的回答,所以我使用Windows Phone Silverlight工具箱尝试了上面的代码,并且该代码有效。 因此,解决方案是使用Windows Phone Silverlight。
通过设置Stretch="None"
,您的代码中只有一个小错误,您不允许图像沿任何方向拉伸,因此始终保持其原始大小。 将“ Stretch
更改为“ Uniform
,它应该可以工作。
这是我用来验证的示例代码:
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Source="/Assets/ApplicationIcon.png" x:Name="testImage" Stretch="Uniform">
<Image.Resources>
<Storyboard x:Name="Animation">
<DoubleAnimation Storyboard.TargetName="testImage" Storyboard.TargetProperty="Height" From="100" To="200" Duration="0:0:1" />
</Storyboard>
</Image.Resources>
</Image>
<Button Content="Expand image" Grid.Row="1" Click="Button_Click"></Button>
</StackPanel>
private void Button_Click(object sender, RoutedEventArgs e)
{
Animation.Begin();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.