2010-10-25 110 views
0

如何通過xaml代碼連續更改圖像源?通過xaml代碼更改圖像源?

+0

「連續」?你什麼意思 ? – 2010-10-25 09:07:51

+0

我想用另一個替換2個圖像,我的意思是我想在1.秒後顯示1.jpg,然後重複它一遍又一遍 – Bahar 2010-10-25 09:15:46

回答

1

的情況下就地:

<Image Source="smiley_stackpanel.png" Stretch="Fill"/> 

如果風格:

<Style TargetType="Image"> 
    <Setter Property="Source" Value="c:\asd.jpg" /> 
</Style> 
0

這主要是從內存中,所以有可能是一個小bug,但基本上,你會想放入兩張圖像,併爲它們的不透明度值製作動畫:

<Grid> 

    <Image x:Name="imgOne" Source="image1.png"> 
     <Image.Triggers> 
      <EventTrigger RoutedEvent="Image.Loaded"> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation 
          Storyboard.TargetName="imgOne" 
          Storyboard.TargetProperty="(Image.Opacity)" 
          To="0" 
          Duration="0:0:1" 
          AutoReverse="True"         
          RepeatBehavior="Forever" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Image.Triggers>  
    </Image> 
    <Image x:Name="imgTwo" Source="image1.png" Opacity="0"> 
     <Image.Triggers> 
      <EventTrigger RoutedEvent="Image.Loaded"> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation 
          Storyboard.TargetName="imgTwo" 
          Storyboard.TargetProperty="(Image.Opacity)" 
          To="1" 
          Duration="0:0:1" 
          AutoReverse="True"         
          RepeatBehavior="Forever" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Image.Triggers>  
    </Image> 


</Grid> 

嚴格地說,您可能不需要第一個動畫un少一些第二張圖片有一些透明區域或者沒有完全覆蓋第一張圖片。

此外,YMMV - 這將是一個資源的食客,因爲它發生得如此之快和經常。