2012-10-17 2 views
2

XAML에서 하나의 이미지 컨트롤을 사용하고 Image의 소스를 다른 1 초 간격으로 스 와이프하여 간단한 애니메이션을 만들고 싶습니다.C# XAML 메트로 이미지 동적 소스

하지만 그렇게하면 이미지가 깜박입니다. 나는 (TimerTick 이벤트 핸들러에서)이 코드를 사용 :

Uri uri = new Uri("ms-appx:/Sprites/Running/" + y++ + ".png", 
       UriKind.RelativeOrAbsolute); 
BitmapImage textureBitmap = new BitmapImage(uri); 

this.ImageHolder.Source = textureBitmap; 

은 어디에서 문제가 될 수 있는가? BitmapImages를 캐시해야합니까?

도움 주셔서 감사합니다.

답변

1

는 XAML에 StoryBoard를 선언하십시오 :

<Storyboard> 
     <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" 
      Storyboard.TargetName="ImageHolder" Storyboard.TargetProperty="Source"> 
      <DiscreteObjectKeyFrame KeyTime="0:0:0" 
       Value="{Binding Source={StaticResource Frame1Image}"/> 
      <DiscreteObjectKeyFrame KeyTime="0:0:1" 
       Value="{Binding Source={StaticResource Frame2Image}"/> 
      <DiscreteObjectKeyFrame KeyTime="0:0:2" 
       Value="{Binding Source={StaticResource Frame3Image}"/> 
      <!-- etc --> 
     </ObjectAnimationUsingKeyFrames> 
    </Storyboard> 

그래서, 당신은 정적 리소스에 스프라이트를 추가하고 스토리 보드를 실행해야합니다.

+0

그래,하지만 스토리 보드를 사용하지 않고하고 싶습니다. 다른 방법이 있습니까? –

+0

애니메이션을 시작하기 전에 이미지를 미리로드 해보십시오. –

+0

'Dictionary '를 인스턴스와 함께 사용하여 미리로드 한 다음 int 인덱스를 사용하여 액세스하는 좋은 방법은 무엇입니까? –

관련 문제