2009-10-05 10 views
10

내 XAML에서 프로 시저가 진행됨에 따라로드 중 ...과 같은 애니메이션 gif를 표시하고 싶습니다. 나는 이것이 내 GIF를로드 할 때 WPF에서 쉽게 수행 할 수 없다는 것을 알았고 첫 번째 프레임을 보여줍니다. WPF에서 애니메이션을 표시하는 가장 좋은 방법은 무엇입니까?WPF에 애니메이션 gif 표시

<wfi:WindowsFormsHost> 
     <winForms:PictureBox x:Name="pictureBoxLoading"> 
     </winForms:PictureBox> 
    </wfi:WindowsFormsHost> 

는 그러나, 나는 WPF에서이 작업을 수행 할 수있는 방법을 찾는 것을 권 해드립니다 :

+0

가능한 중복 실행 계속 [내가 WPF에서 작동하는 애니메이션 GIF를 어떻게합니까?] (http://stackoverflow.com/questions/210922/how-do-i- get-an-animated-gif-to-work-in-wpf) –

+0

[ListView 위에 "로드 중"이미지 추가] (http://stackoverflow.com/questions/1492096/adding-loading-image-on- top-of-listview) – hakre

답변

1

당신은 MediaElement에

<MediaElement LoadedBehavior="Play" Source="path/to.file" /> 

또는 윈폼에있는 PictureBox를 포함 할 수있다. 스토리 보드 및 애니메이션을 살펴보십시오. 당신이 달성하고자하는 것을 알지 못하거나 왜 이것을하고 싶지 않으면, 더 이상의 조언을하기가 어렵습니다.

5

WPF4에서 자신의 키 프레임 이미지 애니메이션을 시뮬레이션 할 수있을 때까지이 문제가 발생했습니다. 먼저, 애니메이션을 일련의 이미지로 분할하고 "Image1.gif", "Image2, gif"등과 같은 제목을 붙입니다. 해당 이미지를 솔루션 리소스로 가져옵니다. 나는 당신이 그들을 이미지의 기본 리소스 위치에 넣었다고 가정하고 있습니다.

이미지 컨트롤을 사용할 것입니다. 다음 XAML 코드를 사용하십시오. 나는 본질적이지 않은 것들을 제거했다.

<Image Name="Image1"> 
    <Image.Triggers> 
     <EventTrigger RoutedEvent="Image.Loaded" 
     <EventTrigger.Actions> 
      <BeginStoryboard> 
       <Storyboard> 
        <ObjectAnimationUsingKeyFrames Duration="0:0:1" Storyboard.TargetProperty="Source" RepeatBehavior="Forever"> 
         <DiscreteObjectKeyFrames KeyTime="0:0:0"> 
         <DiscreteObjectKeyFrame.Value> 
          <BitmapImage UriSource="Images/Image1.gif"/> 
         </DiscreteObjectKeyFrame.Value> 
         </DiscreteObjectKeyFrames> 
        <DiscreteObjectKeyFrames KeyTime="0:0:0.25"> 
         <DiscreteObjectKeyFrame.Value> 
          <BitmapImage UriSource="Images/Image2.gif"/> 
         </DiscreteObjectKeyFrame.Value> 
        </DiscreteObjectKeyFrames> 
        <DiscreteObjectKeyFrames KeyTime="0:0:0.5"> 
         <DiscreteObjectKeyFrame.Value> 
          <BitmapImage UriSource="Images/Image3.gif"/> 
         </DiscreteObjectKeyFrame.Value> 
        </DiscreteObjectKeyFrames> 
        <DiscreteObjectKeyFrames KeyTime="0:0:0.75"> 
         <DiscreteObjectKeyFrame.Value> 
          <BitmapImage UriSource="Images/Image4.gif"/> 
         </DiscreteObjectKeyFrame.Value> 
        </DiscreteObjectKeyFrames> 
        <DiscreteObjectKeyFrames KeyTime="0:0:1"> 
         <DiscreteObjectKeyFrame.Value> 
          <BitmapImage UriSource="Images/Image5.gif"/> 
         </DiscreteObjectKeyFrame.Value> 
        </DiscreteObjectKeyFrames> 
        </ObjectAnimationUsingKeyFrames> 
       </Storyboard> 
      </BeginStoryboard> 
     </EventTrigger.Actions> 
     </EventTrigger> 
    </Image.Triggers> 
</Image> 
+1

나는이 작업을 내가 작업하고 있던 Windows Phone 게임에 채택하고 치료를했습니다! (당신은'EventTrigger's로 할 수는 없지만 코드를 일반 스토리 보드로 옮기십시오.) – GONeale

+0

"DiscreteObjectKeyFrames는 WPF에서 지원되지 않습니다"오류가 발생합니다. –

0

간단히 마우스 오른쪽 .gif 중요 파일을 클릭하고 두 가지 속성 변경 :

빌드 작업 : 포함 리소스

복사 출력 디렉터리는 : 복사의 경우 최근

다음

<MediaElement x:Name="myGif" UnloadedBehavior="Manual" Source="giphy_s.gif" MediaEnded="MediaElement_MediaEnded"/> 

설정하고 이벤트에 대한이의

private void MediaElement_MediaEnded(object sender, RoutedEventArgs e) 
     { 
      myGif.Position = new TimeSpan(0, 0, 1); 
      myGif.Play(); 
     } 
관련 문제