我的项目中有一个从互联网加载的 WPF 图像控件(延迟加载),我想在图像控件中显示初始图像,直到主图像加载。请帮助我
<DataTemplate DataType="{x:Type local:MyData}">
...
<Image Width="50" Height="50" Source="{Binding Path=profile_image_url_https, FallbackValue=profile_image_url_https}" HorizontalAlignment="Left">
...
</DataTemplate>
您也许可以使用它来使其工作TargetNullValue在绑定上,仅在加载时设置图像属性。
e.g.
<BitmapImage x:Key="DefaultImage" UriSource="Images/Error.ico" />
<Image Source="{Binding TestBitmapImage,
TargetNullValue={StaticResource DefaultImage}}" />
private BitmapImage _TestBitmapImage = null;
public BitmapImage TestBitmapImage
{
get { return _TestBitmapImage; }
set
{
if (_TestBitmapImage != value)
{
_TestBitmapImage = value;
PropertyChanged.Notify(() => this.TestBitmapImage);
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var img = new BitmapImage();
img.DownloadCompleted += (s, dcea) =>
{
TestBitmapImage = img;
};
img.BeginInit();
img.UriSource = new Uri("http://www.gravatar.com/avatar/c35af79e54306caedad37141f13de30c?s=128&d=identicon&r=PG");
img.EndInit();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)