我正在尝试使 WPF 中的图像控件在加载源时具有动画效果。
我找到了一个解决方案,为 Windows 8 Metro 开发做准备,它包含 ImageOpened
事件,它在普通 WPF 图像控件中不存在。
你知道有什么方法可以让图片在加载时显示加载动画吗?
也许有一些库具有这种图像控件?
这是我为 Win 8 开发人员找到的 ImageLoader 控件:
<Grid>
<Image x:Name="imgDisplay" Source="{Binding ElementName=parent,Path=Source}"
ImageFailed="OnImageFailed"
ImageOpened="OnImageOpened" />
<ContentControl
Visibility="{Binding ElementName=parent,Path=IsLoading,Converter={StaticResource converter}}"
Content="{Binding ElementName=parent,Path=LoadingContent}"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch" />
<ContentControl Visibility="{Binding ElementName=parent,Path=IsFailed,Converter={StaticResource converter}}"
Content="{Binding ElementName=parent,Path=FailedContent}"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch" />
</Grid>
这里缺少事件处理程序:
void OnImageOpened(object sender, RoutedEventArgs e)
{
this.IsLoading = false;
this.IsLoaded = true;
}
最佳答案
简单的解决方案:将 Image
控件放置在显示加载动画的控件之上(例如,将两者放在同一个 Grid
中)。只要图像没有完全加载,它就是透明的,让加载动画闪耀,加载完成后它会自动隐藏动画。
关于c# - 带有加载动画的 WPF 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29716439/