[英]DoubleAnimation for image with Storyboard.TargetProperty=“Height”
I have read How can I make an Image grow in size (give the illusion of selection) through a WPF animation? 我已经阅读了如何通过WPF动画使图像尺寸增大(赋予选择的错觉)? and tried to change the height of an image with a
DoubleAnimation
but it does not work. 并尝试使用
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" />
This is the button_clicked
function: 这是
button_clicked
函数:
private void button_clicked(object sender, RoutedEventArgs e)
{
show.Begin();
}
[edit]: Because Johan Falk´s answer I tried the above code with the Windows Phone Silverlight toolkit and it works. [edit]:因为Johan Falk的回答,所以我使用Windows Phone Silverlight工具箱尝试了上面的代码,并且该代码有效。 So the solution is to use Windows Phone Silverlight.
因此,解决方案是使用Windows Phone Silverlight。
You just have a small error in your code, by setting Stretch="None"
you don't allow the image to stretch in any direction, hence Always keeping its original size. 通过设置
Stretch="None"
,您的代码中只有一个小错误,您不允许图像沿任何方向拉伸,因此始终保持其原始大小。 Change Stretch
to for example Uniform
and it should work. 将“
Stretch
更改为“ Uniform
,它应该可以工作。
Here is the sample code I used to verify it with: 这是我用来验证的示例代码:
<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.