BitmapImage imageURI = new BitmapImage();
            ///图片A:
            imageURI.BeginInit();
            imageURI.UriSource = new Uri("E:\\mobile\\mobile\\WPF\\ATVM\\ATVM\\bin\\Debug\\pic\\index.jpg", UriKind.Absolute);
            imageURI.EndInit();
            imgAdvertisement.Source = imageURI;如上面代码,我的C# image控件的source使用绝对路径可以显示,如何采用相对路径?
还有WPF的form类型的程序,如何取得exe文件的路径?类似与Application.StartupPath的

解决方案 »

  1.   

    AppDomain.有方法类型于Application.StartupPath你【快速监视】一下
      

  2.   

    在网站根目录下建个专放图片的文件夹:images
    表示网站当前目录的方法:~/
    取图片用相对路径:~/images/a.bmp绝对路径:Server.MapPaht()+"//images//a.bmp"
      

  3.   

    2楼的正解,是AppDomain.CurrentDomain.BaseDirectory,不过不知道image控件能不能采用相对路径?
    3楼,我的是WinForm程序,不是website程序,对你说的不是很明白,不好意思.
      

  4.   

    "../../"这个路径为当前解决方案目录的路径,还要看那个方法支不支持URI路径了 !
      

  5.   

    winform里不支持相对路径的,及时使用AppDomain.CurrentDomain.BaseDirectory得到的也是绝对路径。
      

  6.   

    imageURI.UriSource = new Uri("/项目名;component/Images/left2.png", UriKind.RelativeOrAbsolute);我用这样的写法 实现了  
    希望对楼主有帮助
      

  7.   

    images是项目根目录下的图片文件夹
      

  8.   

      imageURI.UriSource = new Uri("Images/left2.png", UriKind.RelativeOrAbsolute);
     imageURI.UriSource = new Uri("Images/left2.png", UriKind.Relative);
    都可以