Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
440
Using a resource from ISL directly in code
posted

Hi!
AppStylist allows easily add some image resource to ISL file, just from tab Resources:

See screenshot

When resource has been added, a section in ISL file markup appears:
<resource name="VS Test Resource"> <image>...</image> </resource>

Is there a way to get this image from resource file after StyleManager.Load(styleFileName) ? Or we need to write some own class to read it from ISL like from usual xml-file manually? It would be very convenient for us to store some images in a style file, replace them with replacing entire style file, and get them in the code.

We use v. 16.1

Thank you

Parents
No Data
Reply
  • 6158
    Verified Answer
    Offline posted

    Hello,

    In order to gain access to the style libraries resource, you'll first need to create a new instance of an ApplicationStyleLibrary. You can load in the current style library settings using the LoadFromStyleManager() method on the ApplicationStyleLibrary instance. Once the ApplicationStyleLibrary is populated, you now have access to all the resources via the Resources collection. From here you'll need to locate the appropriate resource (by Name), and extract the image. I used the following code in my simple sample to verify this solution:

                ApplicationStyleLibrary styleLibrary = new ApplicationStyleLibrary();
                styleLibrary.LoadFromStyleManager();

                foreach (var resource in styleLibrary.Resources)
                {
                    ResourceSettings res = resource as ResourceSettings;
                    if (res != null)
                    {
                        switch (res.Name)
                        {
                            case "VS Test Resource":
                                img = res.Appearance.GetImage(null);
                                break;
                        }
                    }
                }

    Let me know if you have any questions.

    Chris

Children
No Data