External site for Images

0
0

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
Mitch Stephens

 

  • You must to post comments
0
0

That looks very easy.. I will try it. We can just execute that code on App startup, or redirect if the client changes their mind

 

Thanks

Mitch

  • You must to post comments
0
0

That looks very easy.. I will try it. We can just execute that code on App startup, or redirect if the client changes their mind

 

Thanks

Mitch

  • You must to post comments
0
0

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.

 

  • You must to post comments
0
0

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:

  1. Use the ImageSource and reference the image in the ‘Resources\Images’  (e.g., xx.ImageSource = ‘Resources\images\MyImage.png’)
  2. Add a block of code after the InitializeComponent call that would replace the design-time path for the ImageSource with a fully-qualified URl to the user-selected theme directory (e.g., xx.ImageSource = “https://xxx/MyTheme/MyImage.png”).

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?

Mitch

 

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

Luca,

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,

Mitch

  • You must to post comments
0
0

I just tried your mixin in a test project, I see the images in the designer and can also use them. You don’t have to set the appearance key. The image is the name of the image to set to ImageSource. See screens below.

 

screen-2

 

screen

  • You must to post comments
0
0

Hi Luca,

I tried you suggestion using a few combinations but was unable to get anything to work. Here is my Mixin theme:

 

{
“name”: “IMGs”,

“images”:
{
“baseUrl”: “https://files.hrtms.com/content/public/jdx_images/round_darkgray/”,
“Heart”: “_Heart.png”,
“Flow”: “_Flow.png”
}
}

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?

Thanks

Mitch

  • You must to post comments
0
0

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:

{

“images”: {

“baseUrl”:”http://server/images/”,

“image1”: “something.png”,

}

}

 

Then ImageSource can simply be “image1”.

HTH

 

  • You must to post comments
Showing 9 results
Your Answer

Please first to submit.