initial image in WPF Image Control

后端 未结 1 1098
再見小時候
再見小時候 2021-01-14 16:19

I have a WPF Image Control in my project that loads from internet (lazy loading), i want to show a initial image in Image Control until main image load. plz help me

1条回答
  •  一整个雨季
    2021-01-14 16:41

    You might be able to make it work using TargetNullValue on the binding, only set the image property when it is loaded.

    e.g.

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

    0 讨论(0)
提交回复
热议问题