0

I have the following resource dictionary in my xaml code and I'd like to shorten the path so its not the entire directory. What is the correct way to specify this folder without having to spell out the entire file structure?

<UserControl.Resources>
    <ResourceDictionary>
        <BitmapImage x:Key="1" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/1.jpg"/>
        <BitmapImage x:Key="2" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/2.jpg"/>
        <BitmapImage x:Key="3" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/3.jpg"/>
        <BitmapImage x:Key="4" UriSource="C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/4.jpg"/>
    </ResourceDictionary>
</UserControl.Resources>

2 Answers 2

1

You can use BaseUri property of BitmapImage

<BitmapImage x:Key="1" BaseUri="{x:Static local:GlobalPaths.BasePath}"  UriSource="1.jpg"/>


public class GlobalPaths
{
   public static readonly Uri BasePath = new Uri(@"C:/Users/Nick/Documents/Software/i Ching/iChing/iChing/Hexagram Images/");
}

Or you could set path for each file like this:

<BitmapImage x:Key="1" UriSource="{x:Static local:GlobalPaths.File1}"/>

..Or set path relative to assembly using siteoforigin if that is an option. This is an example how it would look like if there was a file "1.jpg" in the same folder as application exe:

<BitmapImage x:Key="1"   UriSource="pack://siteoforigin:,,,/1.jpg"/>
Sign up to request clarification or add additional context in comments.

Comments

0

I think the proper way is to add them to your solution in separate folder. Set in properties build action Resource enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.