-1

1)我从亚马逊服务器获取图像并在网格视图中显示它,但有些图像不存在,所以我想显示我本地的默认徽标图像。
2)这是在每个网格中显示图像加载进度条的最佳方式

 <Image  Source="defaultimage"   Height="100" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="ImageDisplay"/>
4

1 回答 1

1

好的,让我们从头开始。

在您的应用加载图像期间 - 您的应用必须呈现一些活动。最好的方法是使用进度条。所有新需求 - 只需创建智能自己的控件,女巫将显示进度条,并在加载完成时 - 显示图像。(如果你想可以使用另一个图像而不是进度条)

注意:WP7 的代码

MySmartImage.xaml

    <UserControl x:Class="Test.MySmartImage"
    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"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d"
   >

    <Grid Width="80" Height="80">
        <Border CornerRadius="3" BorderThickness="1" BorderBrush="White" Background="Black">
            <Grid>
                <toolkit:PerformanceProgressBar x:Name="pb" IsIndeterminate="True" Margin="0"  
                    Background="Yellow" Foreground="Yellow" FontSize="20" 
                                                BorderThickness="0" d:LayoutOverrides="GridBox" />
                <Image Width="80" Height="80" Source="{Binding ImageSourse}" 
                       ImageOpened="Image_ImageOpened"/>
            </Grid>
        </Border>
    </Grid>
</UserControl>

在 MySmartImage.cs 中触发时Image_ImageOpened只是隐藏进度条

private void Image_ImageOpened(object sender, System.Windows.RoutedEventArgs e)
        {
            pb.Visibility = Visibility.Collapsed;
        }

以及创建缩略图的其他秘密:
在您将您ViewModel解码ImageSource为嵌套大小时:

get
     {
          return new BitmapImage(....) { DecodePixelWidth = 200 };
     }

希望对你有帮助。

于 2013-09-04T11:53:53.170 回答