2009-11-25 24 views
11

Tôi đang tìm cách thay đổi hình ảnh trong bảng phân cảnh hoặc cụ thể hơn, thay đổi thuộc tính Source của hình ảnh để trỏ đến một tài nguyên hình ảnh mới. Có vẻ là một StringAnimationUsingKeyFramesDiscreteStringKeyFrame nhưng điều này không làm việc (như xa như tôi có thể nói) kể từ khi sở hữu Nguồn Image là loại ImageSourceThay đổi hình ảnh trong khi sử dụng bảng phân cảnh

kịch bản hiện tại của tôi trông như thế này

<Storyboard x:Key="TransitionImage"> 
    <DoubleAnimationUsingKeyFrames 
     BeginTime="00:00:00" 
     Storyboard.TargetName="image" 
     Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0.2"/> 
     <SplineDoubleKeyFrame KeyTime="00:00:01.5000000" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 
    <StringAnimationUsingKeyFrames 
     BeginTime="00:00:00" 
     Storyboard.TargetName="image" 
     Storyboard.TargetProperty="(Image.Source)"> 
     <!-- This does not work --> 
     <DiscreteStringKeyFrame KeyTime="00:00:00.7000000" Value="check_24.png"/> 
    </StringAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames 
     BeginTime="00:00:00" 
     Storyboard.TargetName="image" 
     Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0.2"/> 
     <SplineDoubleKeyFrame KeyTime="00:00:01.5000000" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

và hình ảnh

<Image x:Name="image" 
     Source="delete_24.png" 
     Width="32" Height="32" 
     Margin="8" 
     RenderTransformOrigin="0.5,0.5"> 
    <Image.RenderTransform> 
     <TransformGroup> 
      <ScaleTransform/> 
      <SkewTransform/> 
      <RotateTransform/> 
      <TranslateTransform/> 
     </TransformGroup> 
    </Image.RenderTransform> 
</Image> 

Tôi có thể thay đổi Source hình ảnh như một phần của bảng phân cảnh hoặc tôi không may mắn?

Trả lời

31

Được rồi, tự giải quyết. Dường như bạn phải sử dụng số ObjectAnimationUsingKeyFramesDiscreteObjectKeyFrame như hình bên dưới:

<ObjectAnimationUsingKeyFrames 
    BeginTime="00:00:00" 
    Storyboard.TargetName="image" 
    Storyboard.TargetProperty="(Image.Source)"> 
    <DiscreteObjectKeyFrame KeyTime="00:00:00.7000000"> 
     <DiscreteObjectKeyFrame.Value> 
      <BitmapImage UriSource="check_24.png" /> 
     </DiscreteObjectKeyFrame.Value> 
    </DiscreteObjectKeyFrame> 
</ObjectAnimationUsingKeyFrames> 
Các vấn đề liên quan