【问题标题】:WPF Image with loading animation带有加载动画的 WPF 图像
【发布时间】: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;
}

【问题讨论】:

标签: c# wpf xaml


【解决方案1】:

简单的解决方案:将Image 控件放置在显示加载动画的控件之上(例如,将两者放在同一个Grid 中)。只要图像还没有完全加载,它就是透明的,让加载动画发光,完成加载后它会自动隐藏动画。

【讨论】:

    猜你喜欢
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    相关资源
    最近更新 更多