Dynamic loading of images in WPF

后端 未结 5 1893
执念已碎
执念已碎 2020-12-04 08:28

I have a strange issue with WPF, I was loading images from the disk at runtime and adding them to a StackView container. However, the images were not displayed. After some

5条回答
  •  温柔的废话
    2020-12-04 09:04

    It is because the Creation was delayed. If you want the picture to be loaded immediately, you can simply add this code into the init phase.

    src.CacheOption = BitmapCacheOption.OnLoad;

    like this:

    src.BeginInit();
    src.UriSource = new Uri("picture.jpg", UriKind.Relative);
    src.CacheOption = BitmapCacheOption.OnLoad;
    src.EndInit();
    

提交回复
热议问题