是否可以在从服务器原始加载之前显示默认图像? [英] Is it possible to show default image before original load from server?
本文介绍了是否可以在从服务器原始加载之前显示默认图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在从服务器加载原始图像之前显示默认图像(例如品牌图标).无需编写大量代码即可实现.因为我希望在整个应用程序中具有相同的行为.
I want to show default image (some thing like brand icon) before original image is loaded from server. It is possible with out writing much code. Because I want same behavior in whole app.
或者我们需要为此创建自定义控件.请指导我!
or we need to create custom control for that. Please guide me!
推荐答案
如果您打算在很多不同的地方重用它,创建一个 CustomControl 可能会更容易.
这是一个应该执行此操作的小型用户控件:
If you are going to reuse it at a lot of different place it's probably easier to just create a CustomControl.
Here is a small user control which should do that:
<UserControl x:Class="PhoneApp1.ImageWithLoading"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480"
x:Name="myImageWithLoading">
<Grid x:Name="LayoutRoot" >
<Image x:Name="temporaryImage" Source="/Assets/Loading"/>
<Image Source="{Binding Source,ElementName=myImageWithLoading}" ImageOpened="RemoteImage_OnLoaded"/>
</Grid>
</UserControl>
public partial class ImageWithLoading : UserControl
{
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof (ImageSource), typeof (ImageWithLoading), new PropertyMetadata(default(ImageSource)));
public ImageSource Source
{
get { return (ImageSource) GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }
}
public ImageWithLoading()
{
InitializeComponent();
}
private void RemoteImage_OnLoaded(object sender, RoutedEventArgs e)
{
temporaryImage.Visibility = Visibility.Collapsed;
}
}
这篇关于是否可以在从服务器原始加载之前显示默认图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文