1

I add some pictures as ressource to my project (for example I put them into the folder "ressources"). Now I'm using them with:

<Image Name="_ImageName" Width="100" Height="100" Source="Resources\HalloPicA.png"/> <Image Name="_ImageName" Width="100" Height="100" Source="Resources\HalloPicB.png"/> 

... and so one.

Imagine now I will change the folder "Resources" to "MyResources". The Problem I have to change it everywhere in the XAML-code. Is there a better way existing? In c#-Code I would declare a member variable from typ string like:

privat _FolderName = "Resources"; 

and use this member variable in this way:

Image newImage = Image.FromFile(_FolderName +"HalloPicA.png"); 

Hopefully my problems are clear.

2 Answers 2

2

You can use Property Binding and Value Converters to do this. For example:

 <Image Name="_ImageName" Width="100" Height="100" Source="{Binding Path=imgA, Converter={StaticResource imgPathConverter}}" /> 

Where your imgPathConverter is the class that can convert image name in your "qualified" image path.

Sign up to request clarification or add additional context in comments.

Comments

1

What you can do is to create separate resource dictionary, or put it in Application.Resources, with BitmapImage resources:

<Application ...> <Application.Resources> <BitmapImage UriSource="/MyAssemblyName;component/MyPath/myImage.png" x:Key="imageKey"/> </Application.Resources> </Application> 

and then when you want to use it

<Image Width="100" Height="100" Source="{StaticResource imageKey}"/> 

this way when folder changes you'll need to change it only in one file

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.