WPF Dispay Image From Relative Location

I would like to display an image in my dialog box, which can be located in the directory relative to which .exe is located, for example.

project
- data
 -- logo  //<-- that where the image is located
-bin      //<-- that where the .exe is in

The default image should be included in .exe, but when displaying the dialog, you must first check the \ data \ logo directory, and if you can find the image with the specified file name, then it should be used to display instead of the one inside the .exe.

Any ideas on how to do this?

Thank,

Tabin

0
source share
3 answers

Use pack URI

pack://application:,,,/ReferencedAssembly;component/data/logo/image.png
+1

exe, , , (, c:\program files\MyApp\data\logo). ,

File.Exists("/data/logo/logo.png")

false, .

//

Visual Studio ID,

<Project directory>/bin/debug/data/logo
0

, ,

  // set the logo
  string path = Environment.CurrentDirectory + "\\data\\logo\\logo.gif";
  var uri = new Uri(path, UriKind.Absolute);
  try
  {
    this.myImg.Source = new BitmapImage(uri);
  }
  catch (Exception e)
  {
    this.myImg.Source = new BitmapImage(new Uri(@"pack://application:,,,/myAssemblyName;component/Images/logo.gif"));
  }

, , . , . viewboxes/images?

,

0

All Articles