0

Introduction

So, let's say I build some Application for a client, this application cointans several images, like a logo, several buttons in copropate design, which I want my clients to change freely without having to rebuild the project every time.

Problem

So, I put it into my "image" Folder in my Solution

enter image description here

And set it like this:

            <Image Source="/images/SaveButtonpicture.png" />

Now the logo is located at

MyProject/Images

and either gets packed into the assembly, if set to "Resource" or gets copied to

MyProject/bin/Debug/Images

if set as "Content" with "copy to output directory" is set to "Always"

I don't like the image folder to be at this place. I'd much rather have my logo in

MyProject/bin/Debug/Assets/Images/Logos/

I already worked out a pre-build event to move all logos to there, but I don't know how to create a non static path.

using <Image Source="pack://application:,,,/images/Logo.png" /> would navigate from the solution folder, but that won't work anymore once I hand out the completed version.

Is there an xaml equivalent to System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), that'll return the folder of my executable simular to how pack://application: navigates from the solution folder.

Question

I'd like to find a way to get the correct path without using any c# code

Azzarrel
  • 537
  • 5
  • 20
  • Consider using the image files as assembly resources. Add the files to your Visual Studio project and set their Build Action to Resource. They won't be copied anywhere, but packed into the assembly. – Clemens Jun 05 '19 at 12:48
  • That's not what I hoped for, but works very well for me, too. Still, is there any 'shortcut' to the application dir, like "pack://application:,,," is a shortcut to the solution dir? – Azzarrel Jun 06 '19 at 09:40
  • 1
    Probably [Site of Origin Pack URIs](https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/pack-uris-in-wpf#site-of-origin-pack-uris) – Clemens Jun 06 '19 at 09:45
  • I've reworded my question a little, as - although using the image files as assembly resources is the far better way for my project - I was rather looking for the Site of Origin Pack URI rather than how to load images at runtime. I hope the new example makes this more clear and differs enough from the linked question to not be a duplicate anymore. – Azzarrel Jun 06 '19 at 13:01

0 Answers0