use*_*606 15 wpf xaml windows-phone-7 windows-phone-8
我正在使用绑定作为Image
控件的来源.
<Image Source="{Binding ImageUri}"/>
Run Code Online (Sandbox Code Playgroud)
但是这ImageUri
可能是空的,因此我想使用默认图像,占位符,/Assets/PlaceHolder.png
例如.
如何设置默认图像?谢谢. (这是一个WP8应用程序,但不应该与WPF不同)
Nit*_*esh 23
你可以通过设置来实现它 TargetNullValue
<Image>
<Image.Source>
<Binding Path="ImageUri" >
<Binding.TargetNullValue>
<ImageSource>/Assets/PlaceHolder.png</ImageSource>
</Binding.TargetNullValue>
</Binding>
</Image.Source>
</Image>
Run Code Online (Sandbox Code Playgroud)