how to add images from file location WPF

后端 未结 2 1352
既然无缘
既然无缘 2020-12-31 06:34

Am stuck to load images from my file location in WPF.

here is my xaml



        
相关标签:
2条回答
  • 2020-12-31 06:53

    If it's a file located somewhere on the drive (not a resource), better use an ABSOLUTE path:

    image.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "image.png", UriKind.Absolute));
    

    This code detects the running folder and builds the path relative to it

    0 讨论(0)
  • 2020-12-31 07:02

    Here's the catch

    image1.Source = new BitmapImage(new Uri(filePath));
    
    0 讨论(0)
提交回复
热议问题