【发布时间】:2015-04-18 19:22:18
【问题描述】:
我正在尝试让 WPF 中的 Image 控件在加载源代码时进行动画处理。
我找到了一个解决方案,为 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;
}
【问题讨论】:
-
如果您的
Source是BitmapSource,您可以尝试BitmapSource.DownloadCompleted事件