【问题标题】:Is it possible to show default image before original load from server?是否可以在从服务器原始加载之前显示默认图像?
【发布时间】:2013-10-01 09:53:12
【问题描述】:

我想在从服务器加载原始图像之前显示默认图像(例如品牌图标)。无需编写太多代码即可。因为我希望在整个应用中具有相同的行为。

或者我们需要为此创建自定义控件。请指导我!

【问题讨论】:

    标签: xaml windows-phone-7 windows-phone-8


    【解决方案1】:

    如果您要在很多不同的地方重复使用它,那么创建一个 CustomControl 可能会更容易。
    这是一个应该执行此操作的小型用户控件:

    <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;
        }
    }
    

    【讨论】:

    • 感谢您的回答:)
    • 感谢您的回答。它对我来说非常有效。我正在为ImageBrush 尝试同样的事情。我有一个椭圆。在Ellipse.Fill 属性中,我添加了 ImageBrush。我怎样才能将您的代码用于ImageBrush
    【解决方案2】:

    另一种选择可能是在默认样式页面中为图像创建默认样式,如下所示

    <Style TargetType="Image">
         <Setter Property="Source" Value="/Assets/Load.jpg"/>
    </Style>
    

    当图像准备好时设置源

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-21
      • 2022-10-16
      • 1970-01-01
      • 2013-08-12
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多