.net 是否通过xaml代码更改图像源?
如何通过xaml代码连续更改图像源 在适当的情况下:.net 是否通过xaml代码更改图像源?,.net,wpf,xaml,.net,Wpf,Xaml,如何通过xaml代码连续更改图像源 在适当的情况下: <Image Source="smiley_stackpanel.png" Stretch="Fill"/> 如果是时尚的: <Style TargetType="Image"> <Setter Property="Source" Value="c:\asd.jpg" /> </Style> 这主要来自内存,因此可能有一个小错误,但基本上,您需要放入两个图像,并设置其不透明度值的
<Image Source="smiley_stackpanel.png" Stretch="Fill"/>
如果是时尚的:
<Style TargetType="Image">
<Setter Property="Source" Value="c:\asd.jpg" />
</Style>
这主要来自内存,因此可能有一个小错误,但基本上,您需要放入两个图像,并设置其不透明度值的动画:
<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>
严格来说,您可能不需要第一个动画,除非第二个图像有一些透明区域或没有完全覆盖第一个
此外,YMMV-这将是一个资源消耗者,因为它发生得如此迅速和频繁。“持续”?你是什么意思?我想用另一个图像替换2个图像,我的意思是我想显示1.jpg,一秒钟后,2.jpg,然后一遍又一遍地重复它