How can I change an image source continuously by xaml codes??
A:
in case of in-place:
<Image Source="smiley_stackpanel.png" Stretch="Fill"/>
if in style:
<Style TargetType="Image">
<Setter Property="Source" Value="c:\asd.jpg" />
</Style>
Andrey
2010-10-25 09:13:11
A:
This is mostly from memory, so there may be a small bug, but basically, you'll want to put in two images, and animate their Opacity values:
<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>
Strictly speaking, you probably don't need the first animation unless the second image has some transparent areas or does not fully cover the first.
Also, YMMV - this will be a bit of a resource eater, since it is happening so quickly and often.
Wonko the Sane
2010-10-25 13:03:53