Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为从服务加载的图像设置占位符图像?_C#_Windows Runtime - Fatal编程技术网

C# 如何为从服务加载的图像设置占位符图像?

C# 如何为从服务加载的图像设置占位符图像?,c#,windows-runtime,C#,Windows Runtime,我正在使用绑定作为图像控件的源代码 <Image Source="{Binding ImageUri}"/> 但我的图像源从服务中获取图像,因此加载图像需要时间,同时我想显示我的占位符图像。如何在Winrt应用程序中执行此操作 提前谢谢。我不知道确切的答案。但你可以通过这项工作来做到 将图像放置到网格中,该网格将背景作为默认图像 <Grid Width="104" Height="104" > <Grid.Background> <Imag

我正在使用绑定作为图像控件的源代码

<Image Source="{Binding ImageUri}"/>

但我的图像源从服务中获取图像,因此加载图像需要时间,同时我想显示我的占位符图像。如何在Winrt应用程序中执行此操作


提前谢谢。

我不知道确切的答案。但你可以通过这项工作来做到

将图像放置到网格中,该网格将背景作为默认图像

<Grid Width="104" Height="104" >
<Grid.Background>
    <ImageBrush ImageSource="/Assets/DefaultImage.png"/>
</Grid.Background>
<Image Source="{Binding ImgSrc,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Stretch="Uniform" />

方法1: 此外,还可以将ImageFailed事件用于图像控件。 您可以使用XAML中的行为实现这一点,从而获得一个无麻烦的解决方案

方法2: 您还可以使用Binding.TargetNullValue来实现您的要求

<Image>
    <Image.Source>
        <Binding Path="ImagePath" >
            <Binding.TargetNullValue>
                <ImageSource>/Assets/DefaultImage.png</ImageSource>
            </Binding.TargetNullValue>
        </Binding>
    </Image.Source>
</Image>

/资产/DefaultImage.png
对于UWP,有控制(在中)



当图像源为空时,此选项有效;当图像加载时间时,此选项无效。是否有其他第三方控件自动支持占位符图像。您是否建议使用其他第三方控件
<controls:ImageEx Name="ImageExControl" IsCacheEnabled="True"
  PlaceholderSource="/assets/thumbnails/thumbnails.png"
   Source="/assets/bigPicture.png"/>