change image source by xaml code?
How can I开发者_运维问答 change an image source continuously by xaml codes??
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>
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.
精彩评论