c# - 带有加载动画的 WPF 图像

标签 c# wpf xaml

我正在尝试使 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/

相关文章:

c# - 如何在 Azure DocumentDb 中搜索小写字母?

c# - asp.net核心,EF核心: Dynamically map repository and services in run time

c# - 如何将 Nullable<Boolean> 值传递给 CommandParameter?

c# - C# 中的计算数组值 - 响应式(Reactive)编程

c# - SendInput 不执行单击鼠标按钮,除非我移动光标

c# - 如何将 WPF 中的列表框绑定(bind)到通用列表?

c# - 如何在没有按钮的情况下折叠数据网格?

wpf - Datagrid 行的静态数据是否可以纯粹在 XAML 中定义,即没有代码背后?

silverlight - 使用命名空间 Silverlight/XAML 的具体示例有哪些?

c# - WPF DataGrid 和 DataGridTemplateColumn 标题问题