I want to replace the path part of the source path with a c# constant for easier path management, for example I have:
<Image Source="/Images/Themes/Buttons/MyPicture.png" />
and in another class I have my constant defined:
public static readonly string UriImagesButtons = "/Images/Big/PNG/";
I want to have something along the lines of:
<Image Source="{static:UriImagesButtons + MyPicture.png}" />
This means that I can change the path globally at a stroke if the need arises. What's the syntax to do this?
The easiest way to do this is with a MultiBinding with a StringFormat:
<Path>
<Path.Source>
<MultiBinding StringFormat="{}{0}{1}">
<Binding Mode="OneTime" Source="{x:Static lcl:ConstantOwner.UriImagesButtons}" />
<Binding Mode="OneTime" Source="MyPicture.png" />
</MultiBinding>
</Path.Source>
</Path>
In the StringFormat parameter, you have to escape the first curly brace with a "{}" so the XAML parser doesn't think it is a markup extension.
You should take a look at the discussion on this thread: string manipulation in xaml attribute
Basically, you can create your own markup extension that takes 2 parameters and concatenates them. This particular example is also used for binding. I suspect you'd like to be able to bind to where you have the root path defined, or some other data perhaps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With