Hi WiseJ team,
I would like to externalize all my images in the system and specify a path to the images using the ImageSource property.
It looks like ImageSource will work with external URLS. However, is there a way to specify a base URL at the system level, and then have the option to switch it out without have to impact all of the ImageSource properties? For example: xxx.ImageSource = “@BaseURL@/icons/myimage.png”
The business objective is to allow a client to switch between different image libraries or customize the images that we provide.
Is there an easier way to accomplish this?
Thanks in advance
Redirecting images is either managed by a theme, or a css file that needs to be changed in the html page that swaps images. It’s not easy to generalize that functionality. You’d have to build a sort of image manager. Having said that, I have a solution for you 🙂
I’d still use a single mixin with all your application images urls in there. Set the baseUrl to the default base url, say “images1/”.
In your app you can alter the loaded theme like this:
// retrieve the Images object from the current theme. var prop = Application.Theme.GetType().GetProperty("Images", BindingFlags.NonPublic | BindingFlags.Instance); dynamic images = prop.GetValue(Application.Theme); // change the baseUrl value. images.baseUrl = "images2/"; // to force a reload. // if you alter the theme when the app starts you don't need to reload. Application.Navigate("/");
I tried it and it works well.
Hmm.. It seems that Mixins really aren’t designed to be dynamically controlled by code.
So one other idea I was thinking about was as follows; maybe you could offer advice if it would work:
Basically the idea would be to switch the URL for all images in the form/control right after initialization.
Would that work? Maybe put this code in a base class and use the base class for all forms.
Is there any way to override the InitializeComponent method and have some of my own code running?
Cannot change the mixin by code (unless you write the file and reload and the mixin is not embedded). Mixins and the current theme are loaded and meshed together and then sent to the client only once as a single json file since they styles have to be converted to css and the properties and to be applied to widgets as they are created.
To change the baseUrl you have to change mixin. You can have a mxin with all the icons and the base url. Then have additional mixins that only change the baseUrl. The problem is that if they are all in the same /Themes directory then Wisej will apply all of the them at once.
There is a method overload Application.LoadTheme(theme, mixinx) where you can supply the base theme name and the list of mixins to apply. You can use to apply the base mixin and whichever mixin you want to use to change the baseUrl.
Thanks for showing how to use this!
One last item: Is there a way to switch the “BaseURL” in the Mixin using code?
I am trying to get to a point where the user has the option to switch the theme – and in doing so, they would also pick up a different set of icons.
Maybe there is some other technique to allow that functionality
Thanks in advance,
I tried you suggestion using a few combinations but was unable to get anything to work. Here is my Mixin theme:
I tried without ‘name’ but it still didn’t work.
When trying this on the background image of a form, I set the Appearance Key to the name in the mixin file, but this impacted the whole form.
If I set the ImageSource to the full URL it works fine.
Can you offer any suggestions?
The themes already support that, it’s the “baseUrl” property in the theme files. You could create a mixin “app-images.mixin.theme” and place the indirection in there:
Then ImageSource can simply be “image1”.