Load resources from a working directory rather than from app directory

26 views Asked by At

In my WPF application I'm using a ResourceDictionary to store paths for all assets. Here's the example:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=System.Runtime">
    ...
    <BitmapImage x:Key="SomeKey"
                 UriSource="/MyWPFApp;component/Assets/Images/SomeImage.png" />
    ...
</ResourceDictionary>

No matter how I start the application, it will try to load images (and other assets, such as fonts, videos and sounds) from the application directory, i.e. if my app is located at C:\\MyApp\\MyApp.exe, then the resources are going to be loaded from C:\\MyApp\\Assets\\....

The question is: if I'm starting my app by using a shortcut from a different directory, is it possible to load assets from this folder?

For example, if I have my shortcut to app located at D:\\Shortcuts\\MyAppShortcut.lnk, can I somehow load assets from D:\\Shortcuts\\Assets\\...? I don't want to specify the absolute path for each resource inside the ResourceDictionary since it's a subject to change (i.e. shortcut could be moved to another location).

0

There are 0 answers