2014-12-06 30 views
1

我已閱讀How can I make an Image grow in size (give the illusion of selection) through a WPF animation?並試圖用DoubleAnimation更改圖像的高度,但它不起作用。圖像的DoubleAnimation與Storyboard.TargetProperty =「高度」

<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(); 
} 

[編輯]:因爲約翰Falk's答案,我試圖與Windows Phone的Silverlight工具包上面的代碼和它的作品。所以解決方案是使用Windows Phone Silverlight。

回答

2

您的代碼中只有一個小錯誤,通過設置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(); 
} 
+0

我想用拉伸=「無」,所以不是整個圖像是可見的。試過你的解決方案,即使設置Stretch =「uniform」,它也不起作用。您是否使用Windows Phone Toolkit或Windows Phone Silverlight? – 2014-12-06 22:40:47

+0

我使用了Windows Phone Silverlight。如果您只想「隱藏」圖像的一部分,而不是在更改高度時對其進行拉伸,請將圖像放入StackPanel中,例如將StackPanel的高度設置爲動畫 – 2014-12-06 22:54:52