This is a migrated thread and some comments may be shown as answers.

Dynamically binding external stylesheets

3 Answers 193 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Janitha
Top achievements
Rank 1
Janitha asked on 09 Oct 2018, 07:56 AM

I have created a report where I have several style rules. These style rules are created on style selector and type selector. I have also several exported style rules using the styles used in the report. For example, in the textboxes with style name 'main' have background color as yellow and in my exported style rule the background color is blue for the style name 'main'. In a console application, I am binding these external styles using the following code. 

 

Report report = (Report)xmlSerializer.Deserialize(xmlReader);

 

ExternalStyleSheet ess = new ExternalStyleSheet(this.themeFilePath);
report.ExternalStyleSheets.Add(ess);

 

The issue is even though I add the external style sheet the background color is not changing. But if I delete the style rule from the / file the external style sheet is applied. Is external style sheets does not override the styles that are already defined in the project? If not is there a way to override styles that are already defined in the design? 

 

Thank you

 

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 12 Oct 2018, 07:39 AM
Hi Janitha,

This is an expected behavior since ExternalStyleSheets have lower priority that StyleSheet. Both collections are different, hence there cannot be overriding between them.
If you replace the inline StyleSheet with an ExternalStyleSheet, it should be successfully overridden by the ExternalStyleSheet with the same name added from the code.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Janitha
Top achievements
Rank 1
answered on 12 Oct 2018, 07:48 AM
What do you mean by  'If you replace the inline StyleSheet with an external stylesheet, it should be successfully overridden by the ExternalStyleSheet with the same name added from the code.'Is the name referred here is the style name? So for example, if an inline style rule named headerStyle is applied in the report and I can override this style by using the headerStyle.xml external style sheet?
0
Accepted
Todor
Telerik team
answered on 17 Oct 2018, 07:12 AM
Hello Janitha,

ExternalStyleSheets and StyleSheet are different properties, hence the value assigned to one of them will not override the value assigned to the other. When there are two StyleRules with the same name in the ExternalStyleSheets and StyleSheet, the StyleSheet rule will be prioritized.

If you would like to assign a StyleRule from the code that overrides a rule set in the report definition StyleSheet property, it will be necessary to add a StyleRule with the same name to the report StyleSheet collection :

StyleRule sr = new StyleRule();
sr.Selectors.Add(new StyleSelector("main"));
sr.Style.BackgroundColor = System.Drawing.Color.Blue;
report.StyleSheet.Add(sr);

Alternatively, if you prefer to load the StyleRule 'main' from an .xml file and the rule to override a rule with the same name in the report definition, it will be necessary the StyleRule 'main' to be an item in the report definition ExternalStyleSheets collection (i.e. in report definition the rule to be loaded also from an .xml file). In this case the StyleRule applied from the code behind will override the rule from the report definition, as they will be coming from the same property (ExternalStyleSheets).

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Janitha
Top achievements
Rank 1
Answers by
Todor
Telerik team
Janitha
Top achievements
Rank 1
Share this question
or