Page 1 of 1

Loading styles programatically from a .sts file

Posted: Wed Nov 02, 2011 9:46 am
by John
Hallo Support,

I have a lot of templates saved as .cs classes in my project. In each template there is a list of styles defined which I also keep in a Styles.sts file. If I have to make a global change, for example, my "StyleNormal" should now be 9pt font size instead of 8pt it would be great if I only had to make the change once in my sts file, rather than opening each template and making the change there.
As I understand it, to do this I have to load the styles from Styles.sts at runtime and replace the styles in my template.
This is the code I have tried:

// load my embedded file into a stream
Stream normalStyles = myUtils.GetResourceAsStream("XXX.Styles.sts");

// load my template generically as there are lots of them
Type retType = typeof(T);
var template = (T)Activator.CreateInstance(retType);

// convert to StiReport
StiReport report = template as StiReport;

// remove the existing styles
report.Styles.Clear();

// reset pointer
normalStyles.Position = 0;

// load all styles from the file
report.Styles.Load(this.normalStyles);

This doesn't seem to work as I would have expected so I must be doing something wrong.
For example, when I DON'T load the styles (in the last line of code) and let my report render, the debugger tells me that the Styles collection is empty but when I view the report as a pdf it is still formatted correctly. How does the report still know the style information even though all the styles have been cleared?

When I load the styles from my Styles.sts file there is a problem for any styles which contain a Description node - this text is then used as the name of the style.

Is what I am trying to do possible and if so, how can I be sure that the styles in my template .cs class are completely overwritten?

Thanks and regards,

John Kitching

[P.S. Using latest .net version of Stimulsoft]

Loading styles programatically from a .sts file

Posted: Thu Nov 03, 2011 9:07 am
by Alex K.
Hello,

We check your code and it works.
Please send us a sample project which reproduces the issue for analysis.

Thank you.